CONSTRUCTION
I've got Activity
that holds a "path" made of Fragments
.
The User goes from Fragment1
to Fragment2
and then to Fragment3
filling up the required informations. Nothing fancy here just plain backStack
and .replace
made on Fragments
.
QUESTION
How should I retain that information when orientation changes to get my backStack
back the way it was before orientation change?
IDEAS
The only idea I have is to insert into saveInstanceState
the last visible Fragment
and recreate things from there but it feels really hacky and I think in the long run it's going to make some major problems.
/////////////UPDATE//////////////
It looks like nowadays Android is capable of doing it on its own as long as you are following the guidelines provided by ARTICLE
Another most common solution to dealing with orientation changes by setting the android:configChanges flag on your Activity in AndroidManifest. xml. Using this attribute your Activities won't be recreated and all your views and data will still be there after orientation change.
If you want to manually handle orientation changes in your app you must declare the "orientation" , "screenSize" , and "screenLayout" values in the android:configChanges attributes. You can declare multiple configuration values in the attribute by separating them with a pipe | character.
When you rotate your device and the screen changes orientation, Android usually destroys your application's existing Activities and Fragments and recreates them. Android does this so that your application can reload resources based on the new configuration.
The backstack itself is saved and loaded automatically with the activity. Here's an article how Android does save and load activity and fragment states. What you should care of is implementing the same logic of saving and restoring states for each fragment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With