Android Programming: The Big Nerd Ranch Guide, Third Edition
by Bill Phillips, Chris Stewart, Kristin Marsicano
The Activity Lifecycle, Revisited
Overriding onSaveInstanceState(Bundle) is not just for handling rotation or other runtime configuration changes. An activity can also be destroyed by the OS if the user navigates away for a while and Android needs to reclaim memory (e.g., if the user presses Home and then goes and watches a video or plays a game).
Practically speaking, the OS will not reclaim a visible (paused or resumed) activity. Activities are not marked as “killable” until onStop() is called and finishes executing.
Stopped activities are fair game to be killed, though. Still, not to worry. If an activity is stopped, that means onSaveInstanceState(Bundle) was called. So resolving the data-loss-across-rotation bug also addresses ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access