3 The Activity Lifecycle

What good is an app that resets itself when the user rotates the device? At the end of Chapter 2 you discovered that the geography question displayed is reset to the first question every time the device is rotated, regardless of what question is displayed prior to rotation. In this chapter you will address the dreaded – and very common – rotation problem. To fix it, you will learn the basics of the activity lifecycle.

Every instance of Activity has a lifecycle. During this lifecycle, an activity transitions between four states: resumed, paused, stopped, and nonexistent. For each transition, there is an Activity method that notifies the activity of the change in its state. Figure 3.1 shows ...

Get Android Programming: The Big Nerd Ranch Guide, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.