Saving the activity state for configuration changes
Runtime configuration changes in the Android device cause the activity in the foreground to go through a restart process. This behavior is intended to simplify the process for the activity to reinitialize with alternative resources for the given configuration. As the activity goes through the recreation process, you might lose the user entered data or the current state of the activity. For any such course of events, all the Android applications must retain the activity state quickly and cheaply to avoid undesirable user experience. The following section will help you dive deeper to understand the process to retain the activity state.
With the configuration changes, the activity goes through a series of life cycle methods, such as OnDestroy()
followed by OnCreate()
. On its way, it calls OnSaveInstanceState()
before it destroys the activity so that you can save the activity state data. The application state can be retained during the onCreate...