Saving and restoring the Activity state
In this section, you’ll explore how your Activity saves and restores the state. As you learned in Exercise 2.01 – logging the Activity callbacks, configuration changes, such as rotating the phone, cause the Activity to be recreated.In these scenarios, it is important to preserve the state of the Activity and then restore it. In the next two exercises, you’ll work through an example, ensuring that data is restored using a long-established technique to save and restore Activity state.
Exercise 2.02 – saving and restoring state
In this exercise you are going to create a simple app that generates a random number:
- Create an application called
Save and Restore
with an empty Activity. - Open up the
strings.xml
file (located inapp
|res
|values
|strings.xml
in the Android view of the Project Window or atapp
|src
|main
|res
|values
|strings.xml
in the...