Save state of fragments in backstack

2019-06-20 16:50发布

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.

0条回答
登录 后发表回答