blob: afeab867860c2dd6e9e0dd3fe7b415001238ae8c [file] [log] [blame]
page.title=Managing the Activity Lifecycle
page.tags=activity lifecycle
helpoutsWidget=true
trainingnavtop=true
startpage=true
@jd:body
<div id="tb-wrapper">
<div id="tb">
<h2>Dependencies and prerequisites</h2>
<ul>
<li>How to create an Android project (see <a
href="{@docRoot}training/basics/firstapp/creating-project.html">Creating an Android
Project</a>)</li>
</ul>
<h2>You should also read</h2>
<ul>
<li><a href="{@docRoot}guide/components/activities.html">Activities</a></li>
</ul>
<h2>Try it out</h2>
<div class="download-box">
<a href="http://developer.android.com/shareables/training/ActivityLifecycle.zip"
class="button">Download the demo</a>
<p class="filename">ActivityLifecycle.zip</p>
</div>
</div>
</div>
<p>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).</p>
<p>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.</p>
<p>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.</p>
<h2>Lessons</h2>
<dl>
<dt><b><a href="starting.html">Starting an Activity</a></b></dt>
<dd>Learn the basics about the activity lifecycle, how the user can launch your app, and how
to perform basic activity creation.</dd>
<dt><b><a href="pausing.html">Pausing and Resuming an Activity</a></b></dt>
<dd>Learn what happens when your activity is paused (partially obscured) and resumed and what you
should do during these state changes.</dd>
<dt><b><a href="stopping.html">Stopping and Restarting an Activity</a></b></dt>
<dd>Learn what happens when the user completely leaves your activity and returns to it.</dd>
<dt><b><a href="recreating.html">Recreating an Activity</a></b></dt>
<dd>Learn what happens when your activity is destroyed and how you can rebuild the activity
state when necessary.</dd>
</dl>