Using onSaveInstanceState with fragments in backstack?

前端 未结 4 1479
一向
一向 2020-11-27 15:26

I have fragments I keep in the backstack of FragmentManager. Every fragment state is saved for orientation changes with member variables, like this for example:

<         


        
4条回答
  •  独厮守ぢ
    2020-11-27 16:00

    I think the proper solution is to read those member variables out of savedInstanceState in onCreate which seems to be called always before onSaveInstanceState. If you process the fields in onViewCreated, they don't have the chance to get initialized before the next onSaveInstanceState (in this special case, when Fragment is in the backstack).

提交回复
热议问题