Saving and restoring the Activity state
In this section, you’ll explore how your Activity saves and restores the state. As you’ve learned in the previous section, configuration changes, such as rotating the phone, cause the Activity to be recreated. This can also happen if the system has to kill your app in order to free up memory.
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 the user’s data is restored when TextView
is created and populated from a user’s data after filling in a form.
Exercise 2.02 – saving and restoring the state in layouts
In this exercise, firstly create an application called Save and Restore
with an empty activity. The app you are going to create will have a simple form that offers a discount code for a user’s favorite restaurant if they enter some personal details (no actual information...