Reputation: 32267
I have an activity which contains 2 fragments. I want to save certain state of the activity and also of the fragments, in order to restore if the activity, or the fragments, are destroyed.
So I'm using onSaveInstanceState both in the fragments and in the activity, and take the data of the bundle passed to onCreate or onCreateView.
This works well besides, when the activity is destroyed. Then in restores it's own data, but, since in onCreate() I instantiate the adapter and the fragments again, they get no state.
How do I solve this?
Thanks in advance.
Upvotes: 0
Views: 3668
Reputation: 4297
Most likely the cause of this, is that the Fragment
's onCreateView()
runs before the Activity
's onResume()
according to the Fragment
lifecycle documentation:
http://developer.android.com/guide/components/fragments.html#Creating
Upvotes: 1