• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Managing the Activity Lifecycle
2page.tags=activity lifecycle
3helpoutsWidget=true
4
5trainingnavtop=true
6startpage=true
7
8@jd:body
9
10<div id="tb-wrapper">
11<div id="tb">
12
13
14<h2>Dependencies and prerequisites</h2>
15<ul>
16  <li>How to create an Android project (see <a
17href="{@docRoot}training/basics/firstapp/creating-project.html">Creating an Android
18Project</a>)</li>
19</ul>
20
21
22<h2>You should also read</h2>
23<ul>
24  <li><a href="{@docRoot}guide/components/activities.html">Activities</a></li>
25</ul>
26
27
28<h2>Try it out</h2>
29
30<div class="download-box">
31 <a href="http://developer.android.com/shareables/training/ActivityLifecycle.zip"
32class="button">Download the demo</a>
33 <p class="filename">ActivityLifecycle.zip</p>
34</div>
35
36</div>
37</div>
38
39<p>As a user navigates through, out of, and back to your app, the
40{@link android.app.Activity} instances in your app transition between different states in their
41lifecycle. For instance, when your
42activity starts for the first time, it comes to the foreground of the system and receives user
43focus. During this process, the Android system calls a series of lifecycle methods on the
44activity in which you set up the user interface and other components. If the user performs an
45action that starts another activity or switches to another app, the system calls another set of
46lifecycle methods on your activity as it moves into the background (where the activity is no
47longer visible, but the instance and its state remains intact).</p>
48
49<p>Within the lifecycle callback methods, you can declare how your activity behaves when the
50user leaves and  re-enters the activity.  For example, if you're building a streaming video player,
51you might pause the video and terminate the network connection when the user switches to another
52app. When the user returns, you can reconnect to the network and allow the user to resume the video
53from the same spot.</p>
54
55<p>This class explains important lifecycle callback methods that each {@link
56android.app.Activity} instance receives and how you can use them so your activity does what the
57user expects and does not consume system resources when your activity doesn't need them.</p>
58
59<h2>Lessons</h2>
60
61<dl>
62  <dt><b><a href="starting.html">Starting an Activity</a></b></dt>
63  <dd>Learn the basics about the activity lifecycle, how the user can launch your app, and how
64to perform basic activity creation.</dd>
65  <dt><b><a href="pausing.html">Pausing and Resuming an Activity</a></b></dt>
66  <dd>Learn what happens when your activity is paused (partially obscured) and resumed and what you
67should do during these state changes.</dd>
68  <dt><b><a href="stopping.html">Stopping and Restarting an Activity</a></b></dt>
69  <dd>Learn what happens when the user completely leaves your activity and returns to it.</dd>
70  <dt><b><a href="recreating.html">Recreating an Activity</a></b></dt>
71  <dd>Learn what happens when your activity is destroyed and how you can rebuild the activity
72state when necessary.</dd>
73</dl>
74
75