14.7 Summary
The saving and restoration of dynamic state in an Android application is simply a matter of implementing the appropriate code in the appropriate lifecycle methods. For most user interface views, this is handled automatically by the Activity super class. In other instances, this typically consists of extracting values and settings within the onSaveInstanceState() method and saving the data as key-value pairs within the Bundle object passed through to the activity by the runtime system.
State can be restored in either the onCreate() or the onRestoreInstanceState() methods of the activity by extracting values from the Bundle object and updating the activity based on the stored values.
In this chapter, we have used these techniques to update the StateChange project so that the Activity retains changes through the destruction and subsequent recreation of an activity.