1 page.title= 2 page.tags= 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"> </a></li> 15 <li><a href="#Start">/ </a></li> 16 </ol> 17 18 <h2>. :</h2> 19 <ul> 20 <li><a href="{@docRoot}guide/components/activities.html"></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> 35 , , . 36 .</p> 37 38 <ul> 39 <li> " " . 40 , . 41 , " ", .</li> 42 <li> , . 43 . <em></em> 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()}, 50 . , 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()}. , 58 , {@link 59 android.app.Activity#onPause()} .</p> 60 61 <img src="{@docRoot}images/training/basics/basic-lifecycle-stopped.png" /> 62 <p class="img-caption"><strong> 1.</strong> , 63 {@link android.app.Activity#onStop onStop()} (1). 64 , {@link android.app.Activity#onRestart onRestart()} 65 (2), {@link android.app.Activity#onStart onStart()} (3) {@link 66 android.app.Activity#onResume()} (4). 67 , {@link android.app.Activity#onPause onPause()} {@link 68 android.app.Activity#onStop onStop()}.</p> 69 70 71 72 <h2 id="Stop"> </h2> 73 74 <p> {@link android.app.Activity#onStop()}, 75 , , 76 . , 77 . 78 {@link android.app.Activity#onDestroy()} , 79 {@link android.app.Activity#onStop()} , .</p> 80 81 <p> {@link android.app.Activity#onPause onPause()} 82 {@link android.app.Activity#onStop()}, {@link android.app.Activity#onStop onStop()} 83 , 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> {@link android.app.Activity} 112 . , 113 . 114 {@link android.view.View} , 115 {@link android.widget.EditText}, , 116 .</p> 117 118 <p class="note"><strong>.</strong> , 119 {@link android.view.View} (, {@link 120 android.widget.EditText}) {@link android.os.Bundle} ( "-") 121 , ( <a href="recreating.html"> </a> {@link android.os.Bundle} 122 ).</p> 123 124 125 126 <h2 id="Start">/ </h2> 127 128 <p> , 129 {@link android.app.Activity#onRestart()}. {@link 130 android.app.Activity#onStart()}, , 131 ( ). {@link 132 android.app.Activity#onRestart()} 133 , , 134 , .</p> 135 136 <p> {@link android.app.Activity#onRestart()} 137 , , 138 . {@link android.app.Activity#onStop()} 139 , 140 . 141 ( ). 142 {@link android.app.Activity#onStart()} 143 {@link android.app.Activity#onStop()}, {@link 144 android.app.Activity#onStart()} , 145 .</p> 146 147 <p>, , 148 , {@link android.app.Activity#onStart()} , 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> , {@link android.app.Activity#onDestroy()} 181 {@link android.app.Activity}. 182 {@link android.app.Activity#onStop()} {@link 183 android.app.Activity#onDestroy()}, . 184 , , 185 , , 186 .</p> 187 188