Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

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 the activity lifecycle, states, and
methods.


Figure 3.1  Activity state diagram

Free download pdf