page.title=Managing the Activity Lifecycle trainingnavtop=true startpage=true next.title=Launching an Activity next.link=starting.html @jd:body
ActivityLifecycle.zip
As a user navigates through, out of, and back to your app, the {@link android.app.Activity} instances in your app transition between different states in their lifecycle. For instance, when your activity starts for the first time, it comes to the foreground of the system and receives user focus. During this process, the Android system calls a series of lifecycle methods on the activity in which you set up the user interface and other components. If the user performs an action that starts another activity or switches to another app, the system calls another set of lifecycle methods on your activity as it moves into the background (where the activity is no longer visible, but the instance and its state remains intact).
Within the lifecycle callback methods, you can declare how your activity behaves when the user leaves and re-enters the activity. For example, if you're building a streaming video player, you might pause the video and terminate the network connection when the user switches to another app. When the user returns, you can reconnect to the network and allow the user to resume the video from the same spot.
This class explains important lifecycle callback methods that each {@link android.app.Activity} instance receives and how you can use them so your activity does what the user expects and does not consume system resources when your activity doesn't need them.