Home | History | Annotate | Download | only in activity-lifecycle
      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  UI  UI  () 
     51 
     52 </p>
     53 
     54 <p class="note"><strong></strong> {@link android.app.Activity}  {@link android.app.Activity#onStop()}  {@link android.app.Activity#onRestart()} ( {@link
     55 android.app.Activity#onStart()}) 
     56 
     57  {@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> {@link android.app.Activity#onStop onStop()}  (1)
     63  {@link android.app.Activity#onRestart onRestart()} (2) {@link android.app.Activity#onStart onStart()} (3)  {@link
     64 android.app.Activity#onResume()} (4)
     65 
     66  {@link android.app.Activity#onPause onPause()} {@link
     67 android.app.Activity#onStop onStop()}
     68 </p>
     69 
     70 
     71 
     72 <h2 id="Stop"></h2>
     73 
     74 <p> {@link android.app.Activity#onStop()} 
     75 
     76 
     77  {@link android.app.Activity#onDestroy()}  {@link android.app.Activity#onStop()} 
     78 
     79 </p>
     80 
     81 <p> {@link android.app.Activity#onPause onPause()}  {@link android.app.Activity#onStop()} {@link android.app.Activity#onStop onStop()}  CPU 
     82 
     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 &#64;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  {@link android.view.View}  {@link android.widget.EditText} 
    114 
    115 
    116 </p>
    117 
    118 <p class="note"><strong></strong> {@link android.os.Bundle} ()  {@link android.view.View}  ( {@link
    119 android.widget.EditText} )  (<a href="recreating.html"></a> {@link android.os.Bundle} )
    120 
    121 
    122 </p>
    123 
    124 
    125 
    126 <h2 id="Start">/</h2>
    127 
    128 <p> {@link android.app.Activity#onRestart()} 
    129  {@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  {@link android.app.Activity#onStart()}  {@link android.app.Activity#onStop()}  {@link
    142 android.app.Activity#onStart()}
    143 
    144 
    145 </p>
    146 
    147 <p> {@link android.app.Activity#onStart()} 
    148 
    149 </p>
    150 
    151 <pre>
    152 &#64;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 &#64;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}  {@link android.app.Activity#onDestroy()} 
    181  {@link android.app.Activity#onStop()}  {@link
    182 android.app.Activity#onDestroy()} 
    183  ()
    184 
    185 
    186 </p>
    187 
    188