Android: on screen rotation what should Fragment's onCreate() and onCreateView() do -
in activity have check savedinstancestate, making sure not creating multiple fragments
but question should have similar checks in fragment's oncreate() , oncreateview()
because when rotate screen fragment's oncreate() , oncreateview() called everytime.
question is, ok these 2 methods re-do there job after everyscreen rotation or should have savedinstancestate check well.
right oncreate() makes service call , oncreateview inflates view (recyclerview)
when activity or fragment recreated, oncreate() method first fired, followed onrestoreinstancestate() method, enables retrieve state savedpreviously in onsaveinstancestate() method through bundle object in argument:
@ override public void onrestoreinstancestate(bundle savedinstancestate) { super.onrestoreinstancestate(savedinstancestate); //---retrieve information persisted earlier--- string id = savedinstancestate.getstring(“id”); }
Comments
Post a Comment