The busy coders guide to android development feb 2009

Page 183

Handling Activity Lifecycle Events

Active: the activity was started by the user, is running, and is in the foreground. This is what you're used to thinking of in terms of your activity's operation.

Paused: the activity was started by the user, is running, and is visible, but a notification or something is overlaying part of the screen. During this time, the user can see your activity but may not be able to interact with it. For example, if a call comes in, the user will get the opportunity to take the call or ignore it.

Stopped: the activity was started by the user, is running, but it is hidden by other activities that have been launched or switched to. Your application will not be able to present anything meaningful to the user directly, only by way of a Notification.

Dead: either the activity was never started (e.g., just after a phone reset) or the activity was terminated, perhaps due to lack of available memory.

Life, Death, and Your Activity Android will call into your activity as the activity transitions between the four states listed above. Some transitions may result in multiple calls to your activity, and sometimes Android will kill your application without calling it. This whole area is rather murky and probably subject to change, so pay close attention to the official Android documentation as well as this section when deciding which events to pay attention to and which you can safely ignore. Note that for all of these, you should chain upward and invoke the superclass' edition of the method, or Android may raise an exception.

onCreate() and onCompleteThaw() We have been implementing onCreate() in all of our Activity subclasses in all the examples. This will get called in two situations: 1.

When the activity is first started (e.g., since a system restart), onCreate() will be invoked with a null parameter. 162

This document is licensed for Cheng Po-wen's exclusive use by CommonsWare, LLC


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.