onSaveInstanceState is not being called in Fragment

后端 未结 2 814
小鲜肉
小鲜肉 2020-12-21 01:32

I know that people have asked this question, but I followed all the answers and I still have the same problem. I have two scripts One is the fragment manager (IngredientsAct

2条回答
  •  抹茶落季
    2020-12-21 02:05

    onSaveInstanceState() is only called when the Android system may need to recreate that particular instance of the Fragment. There are many instances of navigating away from the Fragment or even destroying the Fragment where it will not be called. Please consult the documentation for more information, please read the Activity.onSaveInstanceState() documentation as well since that applys here also: http://developer.android.com/reference/android/app/Fragment.html#onSaveInstanceState(android.os.Bundle) http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)

    EDIT: In your case, you must not recreate the fragment every time the user navigates back to the fragment. I recommend considering ViewPager and FragmentPagerAdapter to automatically manage the fragments. Also look at this post: ViewPager and fragments — what's the right way to store fragment's state?

提交回复
热议问题