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="#Stop">Activity</a></li> 15 <li><a href="#Start">/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>ActivityActivityActivityActivity 35 36 </p> 37 38 <ul> 39 <li>Activity 40 Activity 41 </li> 42 <li>ActivityActivityActivity 43 <em></em>Activity 44 </li> 45 <li></li> 46 </ul> 47 48 <p>{@link android.app.Activity} {@link 49 android.app.Activity#onStop()} {@link android.app.Activity#onRestart()}Activity 50 UI UI Activity 51 52 </p> 53 54 <p class="note"><strong></strong> {@link android.app.Activity} 55 56 {@link android.app.Activity#onStop()} {@link android.app.Activity#onRestart()}{@link 57 android.app.Activity#onStart()} Activity Activity {@link 58 android.app.Activity#onPause()} 59 </p> 60 61 <img src="{@docRoot}images/training/basics/basic-lifecycle-stopped.png" /> 62 <p class="img-caption"><strong> 1.</strong>Activity {@link android.app.Activity#onStop onStop()} Activity(1) 63 Activity {@link android.app.Activity#onRestart onRestart()} 64 (2) {@link android.app.Activity#onStart onStart()} (3) {@link 65 android.app.Activity#onResume()} (4) 66 Activity {@link 67 android.app.Activity#onStop onStop()} {@link android.app.Activity#onPause onPause()} 68 </p> 69 70 71 72 <h2 id="Stop">Activity</h2> 73 74 <p>Activity {@link android.app.Activity#onStop()} 75 76 Activity 77 Activity {@link android.app.Activity#onDestroy()} {@link android.app.Activity#onStop()} 78 79 </p> 80 81 <p> {@link android.app.Activity#onPause onPause()} 82 {@link android.app.Activity#onStop()} {@link android.app.Activity#onStop onStop()} 83 CPU 84 </p> 85 86 <p> {@link android.app.Activity#onStop onStop()} 87 </p> 88 89 <!-- TODO: Find a better example for onStop, because this kind of thing should probably use a 90 separate thread but that's too complicated to show here. --> 91 <pre> 92 @Override 93 protected void onStop() { 94 super.onStop(); // Always call the superclass method first 95 96 // Save the note's current draft, because the activity is stopping 97 // and we want to be sure the current note progress isn't lost. 98 ContentValues values = new ContentValues(); 99 values.put(NotePad.Notes.COLUMN_NAME_NOTE, getCurrentNoteText()); 100 values.put(NotePad.Notes.COLUMN_NAME_TITLE, getCurrentNoteTitle()); 101 102 getContentResolver().update( 103 mUri, // The URI for the note to update. 104 values, // The map of column names and new values to apply to them. 105 null, // No SELECT criteria are used. 106 null // No WHERE columns are used. 107 ); 108 } 109 </pre> 110 111 <p>Activity {@link android.app.Activity} Activity 112 113 {@link android.view.View} {@link android.widget.EditText} 114 115 116 </p> 117 118 <p class="note"><strong></strong>ActivityActivity {@link android.os.Bundle} {@link android.view.View} {@link 119 android.widget.EditText} Activity <a href="recreating.html"></a> Activity {@link android.os.Bundle} 120 121 122 </p> 123 124 125 126 <h2 id="Start">/Activity</h2> 127 128 <p>Activity 129 {@link android.app.Activity#onRestart()} Activity {@link 130 android.app.Activity#onStart()} 131 Activity {@link 132 android.app.Activity#onRestart()} Activity 133 134 </p> 135 136 <p> {@link android.app.Activity#onRestart()} Activity 137 138 {@link android.app.Activity#onStop()} 139 ActivityActivity 140 ActivityActivity 141 {@link android.app.Activity#onStart()} 142 {@link android.app.Activity#onStop()} ActivityActivity {@link 143 android.app.Activity#onStart()} 144 145 </p> 146 147 <p> {@link android.app.Activity#onStart()} 148 149 </p> 150 151 <pre> 152 @Override 153 protected void onStart() { 154 super.onStart(); // Always call the superclass method first 155 156 // The activity is either being restarted or started for the first time 157 // so this is where we should make sure that GPS is enabled 158 LocationManager locationManager = 159 (LocationManager) getSystemService(Context.LOCATION_SERVICE); 160 boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 161 162 if (!gpsEnabled) { 163 // Create a dialog here that requests the user to enable GPS, and use an intent 164 // with the android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS action 165 // to take the user to the Settings screen to enable GPS when they click "OK" 166 } 167 } 168 169 @Override 170 protected void onRestart() { 171 super.onRestart(); // Always call the superclass method first 172 173 // Activity being restarted from stopped state 174 } 175 </pre> 176 177 178 179 180 <p>Activity {@link android.app.Activity} {@link android.app.Activity#onDestroy()} 181 {@link android.app.Activity#onStop()} {@link 182 android.app.Activity#onDestroy()} 183 184 185 186 </p> 187 188