Saving the state of fragments in a stack

My problem is usually described in this question: How for everyone, how to properly save the state of the Fragments instance in the background stack?

But I can’t understand how the accepted answer is related to it.

Shortly speaking:

  • There are 2 fragments A and B.

  • I am moving from A to B using a transaction. replace () and add the transaction to the backstack.

  • I rotate the screen -> fragment A is not visible, but it is called onSaveInstanceState - everything is fine to this point.

  • I rotate the screen again. OnSaveInstanceState is called again, but now its view does not exist, so I cannot save it.

What is the purpose of using getFragment / putFragment as the accepted answer suggests? When my fragment is at the back of the table, I don’t think I am referring to it. Thank.

+4
source share

All Articles