java - Activity onStart() being called before Fragment's onActivityCreated() -
i'm having issue fragment's onactivitycreated()
method being called after activity's onstart()
method called. seems imply activity's oncreate()
method finishing after onstart()
? can't case ... can it? when in activity's lifecycle fragment's onactivitycreated()
called? furthermore, if have multiple fragments, how can control order of fragments' onactivitycreated()
calls?
in activity:
@override protected void onstart() { super.onstart(); methoda(); // called ... }
in fragment:
@override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); methodb(); // ... before }
onactivitycreated() method being called after activity's onstart() method called
remember onactivitycreated() method callback fragment activity.
this seems imply activity's oncreate() method finishing after onstart()? can't case ... can it?
wrong! activity , fragment separate, oncreated() method in activity , onactivitycreated() method in fragment not same. above, in fragment it's callback mapping activity state.
let's have @ picture have better understanding.
in official document google: activity onstart()
called before activity becomes visible user. followed onresume() if activity comes foreground, or onstop() if becomes hidden.
fragment callback: onactivitycreated()
called when fragment's activity has been created , fragment's view hierarchy instantiated. can used final initialization once these pieces in place, such retrieving views or restoring state. useful fragments use setretaininstance(boolean) retain instance, callback tells fragment when associated new activity instance. called after oncreateview(layoutinflater, viewgroup, bundle) , before onviewstaterestored(bundle).
the last one:
furthermore, if have multiple fragments, how can control order of fragments' onactivitycreated() calls?
it's depend on way use add fragments activity. order order of added fragments.
Comments
Post a Comment