Save state of fragments in backstack

为君一笑 提交于 2020-01-03 13:40:09

问题


My problem is generally described in this question: Once for all, how to correctly save instance state of Fragments in back stack?

But i can't understand how the accepted answer is related to it.

To keep it short:

  1. There are 2 fragments A and B.

  2. I go from A to B using transaction.replace() and add transaction to backstack.

  3. I rotate screen -> fragment A is not visible, but it's onSaveInstanceState is called - everything ok up to this point.

  4. I rotate screen again. Again A's onSaveInstanceState is called, but now it's view doesn't exist so I can't save it's state.

What's the purpose of using getFragment/putFragment, as accepted answer suggests? When my fragment is in the backstack there's no point in keeping reference to it I guess. Thanks.

来源:https://stackoverflow.com/questions/27062056/save-state-of-fragments-in-backstack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!