1 page.title=Managing the Activity Lifecycle 2 3 trainingnavtop=true 4 startpage=true 5 next.title=Launching an Activity 6 next.link=starting.html 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 17 href="{@docRoot}training/basics/firstapp/creating-project.html">Creating an Android 18 Project</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" 32 class="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 41 lifecycle. For instance, when your 42 activity starts for the first time, it comes to the foreground of the system and receives user 43 focus. During this process, the Android system calls a series of lifecycle methods on the 44 activity in which you set up the user interface and other components. If the user performs an 45 action that starts another activity or switches to another app, the system calls another set of 46 lifecycle methods on your activity as it moves into the background (where the activity is no 47 longer 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 50 user leaves and re-enters the activity. For example, if you're building a streaming video player, 51 you might pause the video and terminate the network connection when the user switches to another 52 app. When the user returns, you can reconnect to the network and allow the user to resume the video 53 from the same spot.</p> 54 55 <p>This class explains important lifecycle callback methods that each {@link 56 android.app.Activity} instance receives and how you can use them so your activity does what the 57 user 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 64 to 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 67 should 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 72 state when necessary.</dd> 73 </dl> 74 75