Fragment lifecycle with respect to it's activity

Vikram Bodicherla picture Vikram Bodicherla · Sep 21, 2011 · Viewed 40k times · Source

Situation My activity waits on an Async operation and after it hears back from async operation, it needs to pass information to 2 fragments inside it.

Requirement 1. Both fragments need their onCreateView calls to be done for them to have their layouts loaded, 2. They need for themselves to be attached to their activity so that getActivity() works.

I wrote a setData() method in both the fragments and am looking for the "correct" place in the activity's lifecycle to invoke them.

onCreate() of the activity does not work, onStart() of the activity does not work and onStart() of the fragment does not work.

Nothing works, what am I missing here?

Answer

Vineet Shukla picture Vineet Shukla · Sep 21, 2011

The official documentation for the Fragment lifecycle explains this clearly - please refer to it and then ask follow-up questions if something is unclear.