Search code examples
androidfragmentandroid-savedstate

checking savedInstanceState state in fragment


Why don't we check savedInstanceState in onCreateView callback of fragment instead of onActivityCreated(Recommended)? According to life cycle of fragment onActivityCreated called after the onCreateView callback in fragment lifecycle.


Solution

  • If you go through this article it is clearly explained that you can call onSaveInstanceState anytime before onDestroy. So to answer your question, you can call that method in onCreateView method also.

    Google Developer Link - Fragment onSaveInstanceState