Saving a fragment on the reverse side when changing orientation

DESIGN

I have Activityone that contains the "path" of Fragments. The user goes from Fragment1to Fragment2and then to Fragment3filling in the required information. Nothing unusual here is simple backStackand .replacedone on Fragments.

Question

How to save this information when changing orientation, to return mine backStackas it was before changing orientation?

IDEAS

The only idea I have is to insert into the saveInstanceStatelast visible Fragmentand recreate things from there, but it feels really hacked, and I think that in the end it will cause some serious problems.

///////////// UPDATE //////////////

It looks like Android is currently able to do this on its own if you follow the recommendations of ARTICLE

+4
source share
1 answer

The trailing stop itself is saved and loaded automatically through the action. Here's an article on how Android saves and loads activity and fragment states. You should take care of implementing the same logic of saving and restoring states for each fragment.

+2
source

Source: https://habr.com/ru/post/1628943/


All Articles