Home | History | Annotate | Download | only in activity-lifecycle
      1 page.title=Activity
      2 page.tags=Activity
      3 helpoutsWidget=true
      4 
      5 trainingnavtop=true
      6 
      7 @jd:body
      8 
      9 
     10 <div id="tb-wrapper">
     11   <div id="tb">
     12 
     13     <h2></h2>
     14 <ol>
     15   <li><a href="#lifecycle-states"></a></li>
     16   <li><a href="#launching-activity">Activity</a></li>
     17   <li><a href="#Create"></a></li>
     18   <li><a href="#Destroy">Activity</a></li>
     19 </ol>
     20 
     21     <h2></h2>
     22     <ul>
     23       <li><a href="{@docRoot}guide/components/activities.html">Activity</a></li>
     24     </ul>
     25 
     26 <h2></h2>
     27 
     28 <div class="download-box">
     29  <a href="http://developer.android.com/shareables/training/ActivityLifecycle.zip" class="button"></a>
     30  <p class="filename">ActivityLifecycle.zip</p>
     31 </div>
     32 
     33   </div>
     34 </div>
     35 
     36 <p> {@code main()} Android  {@link android.app.Activity} 
     37 
     38 
     39 ActivityActivity
     40 </p>
     41 
     42 <p>Activity
     43 </p>
     44 
     45 
     46 
     47 <h2 id="lifecycle-states"></h2>
     48 
     49 <p>Activity
     50 Activity
     51 ActivityActivity
     52 Activity
     53 </p>
     54 
     55 <p>ActivityActivityActivity
     56 ActivityActivityActivity
     57 
     58 
     59 </p>
     60 
     61 
     62 <img src="{@docRoot}images/training/basics/basic-lifecycle.png" />
     63 <p class="img-caption"><strong> 1.</strong>Activity
     64 ActivityActivity
     65 
     66 Activity
     67 </p>
     68 
     69 
     70 <p>Activity
     71 
     72 Activity
     73 </p>
     74 <ul>
     75   <li>
     76 </li>
     77   <li>
     78 </li>
     79   <li>
     80 </li>
     81   <li>
     82 </li>
     83 </ul>
     84 
     85 <!--
     86 <p class="table-caption"><strong>Table 1.</strong> Activity lifecycle state pairs and callback
     87 methods.</p>
     88 <table>
     89   <tr>
     90     <th scope="col">Lifecycle State</th>
     91     <th scope="col">Startup Method</th>
     92     <th scope="col">Teardown Method</th>
     93   </tr>
     94   <tr>
     95     <td>Created / Destroyed</td>
     96     <td>{@link android.app.Activity#onCreate onCreate()}</td>
     97     <td>{@link android.app.Activity#onDestroy()}</td>
     98   </tr>
     99   <tr>
    100     <td>Started / Stopped</td>
    101     <td>{@link android.app.Activity#onStart()}</td>
    102     <td>{@link android.app.Activity#onStop()}</td>
    103   </tr>
    104   <tr>
    105     <td>Resumed / Resumed</td>
    106     <td>{@link android.app.Activity#onResume()}</td>
    107     <td>{@link android.app.Activity#onPause()}</td>
    108   </tr>
    109 </table>
    110 -->
    111 
    112 <p>Activity 1 
    113 
    114 Activity
    115 </p>
    116 <dl>
    117   <dt></dt>
    118     <dd>Activity
    119 </dd>
    120   <dt></dt>
    121     <dd>ActivityActivity&mdash;
    122 Activity
    123 
    124   <dt></dt>
    125     <dd>Activity
    126 Activity
    127 </dd>
    128 </dl>
    129 
    130 <p>
    131 
    132 {@link android.app.Activity#onCreate onCreate()}  {@link
    133 android.app.Activity#onStart()} {@link
    134 android.app.Activity#onResume()}</p>
    135 
    136 <p>
    137 </p>
    138 
    139 
    140 
    141 <h2 id="launching-activity">Activity</h2>
    142 
    143 <p> Activity {@link android.app.Activity}  {@link
    144 android.app.Activity#onCreate onCreate()} 
    145 
    146 Activity</p>
    147 
    148 <p> Android  <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">{@code AndroidManifest.xml}</a> ActivityActivity
    149 </p>
    150 
    151 <p>Activity <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">{@code
    152 <intent-filter>}</a> {@link
    153 android.content.Intent#ACTION_MAIN MAIN} 
    154 {@link android.content.Intent#CATEGORY_LAUNCHER LAUNCHER} </p>
    155 
    156 <pre>
    157 &lt;activity android:name=".MainActivity" android:label="&#64;string/app_name">
    158     &lt;intent-filter>
    159         &lt;action android:name="android.intent.action.MAIN" />
    160         &lt;category android:name="android.intent.category.LAUNCHER" />
    161     &lt;/intent-filter>
    162 &lt;/activity>
    163 </pre>
    164 
    165 <p class="note"><strong></strong> Android SDK Android  {@link android.app.Activity} 
    166 
    167 </p>
    168 
    169 <p>Activity {@link android.content.Intent#ACTION_MAIN MAIN} 
    170 {@link android.content.Intent#CATEGORY_LAUNCHER LAUNCHER} 
    171 </p>
    172 
    173 
    174 
    175 <h2 id="Create"></h2>
    176 
    177 <p>ActivityActivityActivityActivityActivity {@link
    178 android.app.Activity#onCreate onCreate()}  {@link android.app.Activity} 
    179 
    180 
    181 </p>
    182 
    183 <p> {@link android.app.Activity#onCreate onCreate()} Activity
    184  {@link android.app.Activity#onCreate onCreate()} 
    185 
    186 </p>
    187 
    188 <p>{@link android.app.Activity#onCreate onCreate()}
    189 Activity XML  UI
    190 
    191 </p>
    192 
    193 <pre>
    194 TextView mTextView; // Member variable for text view in the layout
    195 
    196 &#64;Override
    197 public void onCreate(Bundle savedInstanceState) {
    198     super.onCreate(savedInstanceState);
    199 
    200     // Set the user interface layout for this Activity
    201     // The layout file is defined in the project res/layout/main_activity.xml file
    202     setContentView(R.layout.main_activity);
    203 
    204     // Initialize member TextView so we can manipulate it later
    205     mTextView = (TextView) findViewById(R.id.text_message);
    206 
    207     // Make sure we're running on Honeycomb or higher to use ActionBar APIs
    208     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    209         // For the main activity, make sure the app icon in the action bar
    210         // does not behave as a button
    211         ActionBar actionBar = getActionBar();
    212         actionBar.setHomeButtonEnabled(false);
    213     }
    214 }
    215 </pre>
    216 
    217 <p class="caution"><strong></strong> {@link android.os.Build.VERSION#SDK_INT}
    218  Android 2.0 API 5 API 
    219 </p>
    220 
    221 <p> {@link android.app.Activity#onCreate onCreate()}  {@link android.app.Activity#onStart()}  {@link android.app.Activity#onResume()} 
    222 
    223 ActivityActivity {@link android.app.Activity#onStart()} 
    224 {@link android.app.Activity#onResume()}ActivityActivity
    225 
    226 
    227 </p>
    228 
    229 <p>ActivityActivity{@link
    230 android.app.Activity#onStart()}  {@link android.app.Activity#onResume()} Activity
    231 </p>
    232 
    233 <p class="note"><strong></strong>{@link android.app.Activity#onCreate onCreate()}
    234  <code>savedInstanceState</code> <a href="recreating.html">Activity</a>
    235 </p>
    236 
    237 
    238 <img src="{@docRoot}images/training/basics/basic-lifecycle-create.png" />
    239 <p class="img-caption"><strong> 2.</strong>Activity
    240 Activity{@link android.app.Activity#onCreate onCreate()}{@link
    241 android.app.Activity#onStart()}  {@link android.app.Activity#onResume()}
    242 ActivityActivityActivity
    243 
    244 </p>
    245 
    246 
    247 
    248 
    249 
    250 
    251 
    252 <h2 id="Destroy">Activity</h2>
    253 
    254 <p>Activity {@link android.app.Activity#onCreate
    255 onCreate()}  {@link android.app.Activity#onDestroy}ActivityActivity
    256 
    257 </p>
    258 
    259 <p>ActivityActivity {@link
    260 android.app.Activity#onPause}  {@link android.app.Activity#onStop} 
    261 Activity {@link
    262 android.app.Activity#onCreate onCreate()}   {@link
    263 android.app.Activity#onDestroy} 
    264 
    265 </p>
    266 
    267 <pre>
    268 &#64;Override
    269 public void onDestroy() {
    270     super.onDestroy();  // Always call the superclass
    271 
    272     // Stop method tracing that the activity started during onCreate()
    273     android.os.Debug.stopMethodTracing();
    274 }
    275 </pre>
    276 
    277 <p class="note"><strong></strong> {@link android.app.Activity#onPause}  {@link
    278 android.app.Activity#onStop}  {@link android.app.Activity#onDestroy}
    279  {@link android.app.Activity#onCreate onCreate()}
    280   {@link
    281 android.app.Activity#finish()} ActivityActivity {@link
    282 android.app.Activity#onCreate onCreate()}  {@link android.app.Activity#finish()} Activity
    283  {@link android.app.Activity#onDestroy} 
    284 
    285 </p>
    286