1 page.title=Activity 2 page.tags=Activity 3 helpoutsWidget=true 4 5 trainingnavtop=true 6 7 @jd:body 8 9 <div id="tb-wrapper"> 10 <div id="tb"> 11 12 <h2></h2> 13 <ol> 14 <li><a href="#Pause">Activity</a></li> 15 <li><a href="#Resume">Activity</a></li> 16 </ol> 17 18 <h2></h2> 19 <ul> 20 <li><a href="{@docRoot}guide/components/activities.html">Activity</a> 21 </li> 22 </ul> 23 24 <h2></h2> 25 26 <div class="download-box"> 27 <a href="http://developer.android.com/shareables/training/ActivityLifecycle.zip" class="button"></a> 28 <p class="filename">ActivityLifecycle.zip</p> 29 </div> 30 31 </div> 32 </div> 33 34 <p>ActivityActivity<em></em> 35 ActivityActivityActivity 36 Activity 37 </p> 38 39 <p>Activity<em></em> 40 </p> 41 42 <p>Activity {@link android.app.Activity} {@link 43 android.app.Activity#onPause onPause()} ActivityActivity 44 {@link android.app.Activity#onResume onResume()} 45 46 47 </p> 48 49 <p class="note"><strong></strong>Activity {@link 50 android.app.Activity#onPause()} Activity 51 ActivityActivity 52 </p> 53 54 <img src="{@docRoot}images/training/basics/basic-lifecycle-paused.png" /> 55 <p class="img-caption"><strong> 1.</strong>ActivityActivity {@link android.app.Activity#onPause onPause()} Activity (1) 56 57 ActivityActivity {@link android.app.Activity#onResume onResume()} (2) 58 </p> 59 60 61 <h2 id="Pause">Activity</h2> 62 63 <p>Activity {@link android.app.Activity#onPause()} ActivityActivity 64 65 66 {@link android.app.Activity#onPause()} </p> 67 68 <ul> 69 <li> CPU </li> 70 <li> 71 </li> 72 <li> GPS Activity 73 74 </li> 75 </ul> 76 77 <p> {@link android.hardware.Camera} 78 {@link android.app.Activity#onPause()} </p> 79 80 <pre> 81 @Override 82 public void onPause() { 83 super.onPause(); // Always call the superclass method first 84 85 // Release the Camera because we don't need it when paused 86 // and other activities might need to use it. 87 if (mCamera != null) { 88 mCamera.release() 89 mCamera = null; 90 } 91 } 92 </pre> 93 94 <p><strong></strong> {@link android.app.Activity#onPause()} 95 {@link android.app.Activity#onPause()} {@link 96 android.app.Activity#onPause()} CPU Activity 97 {@link android.app.Activity#onStop onStop()} 98 99 100 101 </p> 102 103 <p> {@link android.app.Activity#onPause 104 onPause()} Activity 105 </p> 106 107 <p class="note"><strong></strong>Activity{@link 108 android.app.Activity} Activity 109 110 </p> 111 112 113 114 <h2 id="Resume">Activity</h2> 115 116 <p>Activity {@link 117 android.app.Activity#onResume()} </p> 118 119 <p>Activity 120 {@link 121 android.app.Activity#onResume()} {@link 122 android.app.Activity#onPause()} ActivityActivity 123 124 </p> 125 126 <p>{@link android.app.Activity#onResume()} 127 {@link android.app.Activity#onPause()} Activity 128 </p> 129 130 <pre> 131 @Override 132 public void onResume() { 133 super.onResume(); // Always call the superclass method first 134 135 // Get the Camera instance as the activity achieves full user focus 136 if (mCamera == null) { 137 initializeCamera(); // Local method to handle camera init 138 } 139 } 140 </pre> 141 142 143 144 145 146 147 148