How to maintain state values when Android changes configuration
A step by step guide on keeping state values within an Activity during configuration changes such as a change in screen orientation, language or input devices.
What is happening ?
Tutorial
The following tutorial demonstrates how to maintain the experience state state value of the MainActivity in our Open Source project. This makes sure that the app shows the user the same screen as they were on after an orientation change.
If you wish to test it, download the project through the repository linked below.
Step One: Create the Key(s)
We recommend creating a file per activity in your project and creating a string that serves as a type-checked constant for saving and retrieving states.
Step Two: Save the State(s)
In the relevant activity, save the state(s) using the key(s) created in Step One.
Step Three: Restore the State(s)
In the same activity, restore the state(s) using the key(s) created in Step One.
Step Four: Test
Run the app and confirm that the states persist when the Android configuration changes.