July 2015
Beginner to intermediate
600 pages
18h 59m
English
Overriding onSaveInstanceState(Bundle) is not just for handling rotation. An activity can also be destroyed if the user navigates away for a while and Android needs to reclaim memory.
Android will never destroy a running activity to reclaim memory – the activity must be in the paused or stopped state to be destroyed. If an activity is paused or stopped, then its onSaveInstanceState(…) method has been called.
When onSaveInstanceState(…) is called, the data is saved to the Bundle object. That Bundle object is then stuffed into your activity’s activity record by the OS.
To understand the activity record, let’s add a stashed state to the activity lifecycle (Figure 3.13).
Figure 3.13 The ...
Read now
Unlock full access