1 page.title= 2 page.tags= 3 4 @jd:body 5 6 <div id="qv-wrapper"> 7 <div id="qv"> 8 9 <h2></h2> 10 <ol> 11 <li><a href="#Processes"></a> 12 <ol> 13 <li><a href="#Lifecycle"></a></li> 14 </ol> 15 </li> 16 <li><a href="#Threads"></a> 17 <ol> 18 <li><a href="#WorkerThreads"></a></li> 19 <li><a href="#ThreadSafe"></a></li> 20 </ol> 21 </li> 22 <li><a href="#IPC"></a></li> 23 </ol> 24 25 </div> 26 </div> 27 28 <p>Android Linux 29 30 () 31 () 32 33 34 35 </p> 36 37 <p> Android </p> 38 39 40 <h2 id="Processes"></h2> 41 42 <p> 43 44 </p> 45 46 <p> — <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code 47 <activity>}</a><a href="{@docRoot}guide/topics/manifest/service-element.html">{@code 48 <service>}</a><a href="{@docRoot}guide/topics/manifest/receiver-element.html">{@code 49 <receiver>}</a> <a href="{@docRoot}guide/topics/manifest/provider-element.html">{@code 50 <provider>}</a> — {@code android:process} 51 52 53 {@code android:process} Linux ID 54 55 </p> 56 57 <p><a href="{@docRoot}guide/topics/manifest/application-element.html">{@code 58 <application>}</a> {@code android:process} 59 </p> 60 61 <p>Android 62 63 64 </p> 65 66 <p>Android 67 Activity Activity 68 69 70 </p> 71 72 73 <h3 id="Lifecycle"></h3> 74 75 <p>Android 76 77 78 79 80 81 </p> 82 83 <p> (<em></em><em></em>) 84 85 </p> 86 87 <ol> 88 <li><b></b> 89 <p> 90 </p> 91 92 <ul> 93 <li> {@link android.app.Activity} ( {@link 94 android.app.Activity} {@link android.app.Activity#onResume onResume()} ) 95 </li> 96 97 <li> {@link android.app.Service} Activity 98 </li> 99 100 <li> {@link android.app.Service} ( {@link android.app.Service#startForeground startForeground()}) 101 102 103 <li> {@link android.app.Service} ({@link android.app.Service#onCreate onCreate()}{@link android.app.Service#onStart onStart()} {@link android.app.Service#onDestroy onDestroy()}) 104 105 </li> 106 107 <li> {@link android.content.BroadcastReceiver} {@link 108 android.content.BroadcastReceiver#onReceive onReceive()} </li> 109 </ul> 110 111 <p> 112 113 114 </p></li> 115 116 <li><b></b> 117 <p> 118 119 </p> 120 121 <ul> 122 <li> {@link android.app.Activity} ( {@link android.app.Activity#onPause onPause()} ) 123 Activity Activity 124 125 </li> 126 127 <li> {@link android.app.Service} () Activity 128 </li> 129 </ul> 130 131 <p> 132 </p> 133 </li> 134 135 <li><b></b> 136 <p> {@link 137 android.content.Context#startService startService()} 138 () 139 140 141 </p> 142 </li> 143 144 <li><b></b> 145 <p> Activity ( Activity 146 {@link android.app.Activity#onStop onStop()} ) 147 148 149 LRU () Activity 150 151 Activity Activity Activity 152 153 154 <a href="{@docRoot}guide/components/activities.html#SavingActivityState">Activity</a> 155 </p> 156 </li> 157 158 <li><b></b> 159 <p> 160 161 162 </p> 163 </li> 164 </ol> 165 166 167 <p>Android 168 Activity 169 </p> 170 171 <p> 172 173 A B A B A B 174 175 </p> 176 177 <p> Activity Activity <a href="{@docRoot}guide/components/services.html"></a> — Activity Activity Activity Activity 178 179 180 181 182 183 184 </p> 185 186 187 188 189 <h2 id="Threads"></h2> 190 191 <p> 192 193 Android UI ({@link 194 android.widget} {@link android.view} ) 195 UI 196 </p> 197 198 <p><em></em> UI 199 200 ( {@link android.view.View#onKeyDown onKeyDown()} ) UI 201 202 </p> 203 204 <p> UI 205 206 UI 207 </p> 208 209 <p> 210 UI UI () 211 212 213 214 UI ( 5 )<a href="http://developer.android.com/guide/practices/responsiveness.html"></a>(ANR) 215 216 217 </p> 218 219 <p>Andoid UI <em></em> UI — UI 220 221 Android </p> 222 223 <ol> 224 <li> UI 225 <li> UI Android UI 226 </ol> 227 228 <h3 id="WorkerThreads"></h3> 229 230 <p> UI UI 231 () 232 233 </p> 234 235 <p> {@link android.widget.ImageView} 236 </p> 237 238 <pre> 239 public void onClick(View v) { 240 new Thread(new Runnable() { 241 public void run() { 242 Bitmap b = loadImageFromNetwork("http://example.com/image.png"); 243 mImageView.setImageBitmap(b); 244 } 245 }).start(); 246 } 247 </pre> 248 249 <p> 250 UI Android UI <em></em>— {@link 251 android.widget.ImageView} UI 252 253 </p> 254 255 <p>Android UI 256 </p> 257 258 <ul> 259 <li>{@link android.app.Activity#runOnUiThread(java.lang.Runnable) 260 Activity.runOnUiThread(Runnable)}</li> 261 <li>{@link android.view.View#post(java.lang.Runnable) View.post(Runnable)}</li> 262 <li>{@link android.view.View#postDelayed(java.lang.Runnable, long) View.postDelayed(Runnable, 263 long)}</li> 264 </ul> 265 266 <p> {@link 267 android.view.View#post(java.lang.Runnable) View.post(Runnable)} </p> 268 269 <pre> 270 public void onClick(View v) { 271 new Thread(new Runnable() { 272 public void run() { 273 final Bitmap bitmap = loadImageFromNetwork("http://example.com/image.png"); 274 mImageView.post(new Runnable() { 275 public void run() { 276 mImageView.setImageBitmap(bitmap); 277 } 278 }); 279 } 280 }).start(); 281 } 282 </pre> 283 284 <p> UI {@link android.widget.ImageView} 285 </p> 286 287 <p> 288 {@link android.os.Handler} UI 289 290 {@link android.os.AsyncTask} UI 291 </p> 292 293 294 <h4 id="AsyncTask"> AsyncTask</h4> 295 296 <p>{@link android.os.AsyncTask} 297 UI / 298 </p> 299 300 <p> {@link android.os.AsyncTask} {@link 301 android.os.AsyncTask#doInBackground doInBackground()} 302 UI {@link 303 android.os.AsyncTask#onPostExecute onPostExecute()} {@link 304 android.os.AsyncTask#doInBackground doInBackground()} UI UI 305 UI {@link android.os.AsyncTask#execute execute()} 306 </p> 307 308 <p> {@link android.os.AsyncTask} 309 </p> 310 311 <pre> 312 public void onClick(View v) { 313 new DownloadImageTask().execute("http://example.com/image.png"); 314 } 315 316 private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { 317 /** The system calls this to perform work in a worker thread and 318 * delivers it the parameters given to AsyncTask.execute() */ 319 protected Bitmap doInBackground(String... urls) { 320 return loadImageFromNetwork(urls[0]); 321 } 322 323 /** The system calls this to perform work in the UI thread and delivers 324 * the result from doInBackground() */ 325 protected void onPostExecute(Bitmap result) { 326 mImageView.setImageBitmap(result); 327 } 328 } 329 </pre> 330 331 <p> UI UI 332 </p> 333 334 <p> {@link android.os.AsyncTask} 335 </p> 336 337 <ul> 338 <li> 339 </li> 340 <li>{@link android.os.AsyncTask#doInBackground doInBackground()} 341 </li> 342 <li>{@link android.os.AsyncTask#onPreExecute onPreExecute()}{@link 343 android.os.AsyncTask#onPostExecute onPostExecute()} {@link 344 android.os.AsyncTask#onProgressUpdate onProgressUpdate()} UI </li> 345 <li>{@link android.os.AsyncTask#doInBackground doInBackground()} 346 {@link android.os.AsyncTask#onPostExecute onPostExecute()}</li> 347 <li> {@link 348 android.os.AsyncTask#doInBackground doInBackground()} {@link android.os.AsyncTask#publishProgress publishProgress()} UI {@link 349 android.os.AsyncTask#onProgressUpdate onProgressUpdate()}</li> 350 <li></li> 351 </ul> 352 353 <p class="caution"><strong></strong><a href="{@docRoot}guide/topics/resources/runtime-changes.html"></a> () Activity 354 355 <a href="http://code.google.com/p/shelves/">Shelves</a> Activity 356 357 </p> 358 359 360 <h3 id="ThreadSafe"></h3> 361 362 <p> 363 </p> 364 365 <p><a href="{@docRoot}guide/components/bound-services.html"></a> {@link android.os.IBinder IBinder} {@link android.os.IBinder} 366 367 368 369 {@link android.os.IBinder 370 IBinder} ( UI ) 371 {@link android.app.Service#onBind onBind()} UI {@link android.app.Service#onBind 372 onBind()} 373 374 375 {@link android.os.IBinder IBinder} {@link android.os.IBinder 376 IBinder} </p> 377 378 <p> 379 {@link android.content.ContentResolver} {@link android.content.ContentProvider} 380 {@link 381 android.content.ContentProvider} — {@link 382 android.content.ContentProvider#query query()}{@link android.content.ContentProvider#insert 383 insert()}{@link android.content.ContentProvider#delete delete()}{@link 384 android.content.ContentProvider#update update()} {@link android.content.ContentProvider#getType 385 getType()} — UI 386 387 </p> 388 389 390 <h2 id="IPC"></h2> 391 392 <p>Android (RPC) (IPC) RPC () Activity 393 394 395 396 397 398 Android IPC RPC 399 </p> 400 401 <p> IPC {@link 402 android.content.Context#bindService bindService()} <a href="{@docRoot}guide/components/services.html"></a></p> 403 404 405 <!-- 406 <h2>Beginner's Path</h2> 407 408 <p>For information about how to perform work in the background for an indefinite period of time 409 (without a user interface), continue with the <b><a 410 href="{@docRoot}guide/components/services.html">Services</a></b> document.</p> 411 --> 412