Home | History | Annotate | Download | only in components
      1 page.title=
      2 @jd:body
      3 
      4 <div id="qv-wrapper">
      5 <ol id="qv">
      6 <h2></h2>
      7 <ol>
      8 <li><a href="#Basics"></a></li>
      9 <ol>
     10   <li><a href="#Declaring"></a></li>
     11 </ol>
     12 <li><a href="#CreatingAService"></a>
     13   <ol>
     14     <li><a href="#ExtendingIntentService"> IntentService </a></li>
     15     <li><a href="#ExtendingService"></a></li>
     16     <li><a href="#StartingAService"></a></li>
     17     <li><a href="#Stopping"></a></li>
     18   </ol>
     19 </li>
     20 <li><a href="#CreatingBoundService"></a></li>
     21 <li><a href="#Notifications"></a></li>
     22 <li><a href="#Foreground"></a></li>
     23 <li><a href="#Lifecycle"></a>
     24 <ol>
     25   <li><a href="#LifecycleCallbacks"></a></li>
     26 </ol>
     27 </li>
     28 </ol>
     29 
     30 <h2></h2>
     31 <ol>
     32   <li>{@link android.app.Service}</li>
     33   <li>{@link android.app.IntentService}</li>
     34 </ol>
     35 
     36 <h2></h2>
     37 <ol>
     38   <li><a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/app/ServiceStartArguments.html">{@code
     39       ServiceStartArguments}</a></li>
     40   <li><a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/app/LocalService.html">{@code
     41       LocalService}</a></li>
     42 </ol>
     43 
     44 <h2></h2>
     45 <ol>
     46 <li><a href="{@docRoot}guide/components/bound-services.html"></a></li>
     47 </ol>
     48 
     49 </div>
     50 
     51 
     52 <p>{@link android.app.Service}
     53 
     54 
     55  (IPC)
     56  I/O
     57 
     58 </p>
     59 
     60 <p></p>
     61 
     62 <dl>
     63   <dt></dt>
     64   <dd> Activity
     65 {@link android.content.Context#startService startService()} 
     66 
     67 
     68 
     69 </dd>
     70   <dt></dt>
     71   <dd> {@link
     72 android.content.Context#bindService bindService()} - (IPC)
     73 
     74 
     75 
     76 </dd>
     77 </dl>
     78 
     79 <p>{@link
     80 android.app.Service#onStartCommand onStartCommand()} {@link
     81 android.app.Service#onBind onBind()}
     82 
     83 </p>
     84 
     85 <p> {@link android.content.Intent} 
     86 
     87 
     88 <a href="#Declaring"></a>
     89 
     90 </p>
     91 
     92 <p class="caution"><strong></strong><strong></strong><strong></strong>
     93 
     94 
     95 CPU  MP3
     96 (ANR)
     97  Activity 
     98 </p>
     99 
    100 
    101 <h2 id="Basics"></h2>
    102 
    103 <div class="sidebox-wrapper">
    104 <div class="sidebox">
    105   <h3></h3>
    106   <p>
    107 
    108 </p>
    109   <p>
    110  Activity 
    111 {@link android.app.Activity#onCreate onCreate()}
    112  {@link
    113 android.app.Activity#onStart onStart()}  {@link android.app.Activity#onStop
    114 onStop()} 
    115 {@link android.os.AsyncTask}  {@link android.os.HandlerThread} {@link java.lang.Thread} <a href="{@docRoot}guide/components/processes-and-threads.html#Threads"></a>
    116 </p>
    117   <p>
    118 
    119 </p>
    120 </div>
    121 </div>
    122 
    123 <p>
    124 {@link android.app.Service} 
    125 
    126 </p>
    127 
    128 <dl>
    129   <dt>{@link android.app.Service#onStartCommand onStartCommand()}</dt>
    130     <dd> Activity
    131 {@link android.content.Context#startService
    132 startService()} 
    133 
    134 {@link android.app.Service#stopSelf stopSelf()}  {@link
    135 android.content.Context#stopService stopService()} 
    136 </dd>
    137   <dt>{@link android.app.Service#onBind onBind()}</dt>
    138     <dd> {@link android.content.Context#bindService
    139 bindService()}
    140  RPC
    141 {@link android.os.IBinder}  null
    142 </dd>
    143   <dt>{@link android.app.Service#onCreate()}</dt>
    144     <dd>
    145 {@link android.app.Service#onStartCommand onStartCommand()} 
    146 {@link android.app.Service#onBind onBind()} 
    147 </dd>
    148   <dt>{@link android.app.Service#onDestroy()}</dt>
    149     <dd>
    150 
    151 </dd>
    152 </dl>
    153 
    154 <p> {@link
    155 android.content.Context#startService startService()}  {@link
    156 android.app.Service#onStartCommand onStartCommand()} 
    157 {@link android.app.Service#stopSelf()}
    158  {@link android.content.Context#stopService stopService()} </p>
    159 
    160 <p>
    161 {@link android.content.Context#bindService bindService()} <em></em>
    162 {@link
    163 android.app.Service#onStartCommand onStartCommand()}
    164 </p>
    165 
    166 <p> Activity Android
    167  Activity<a href="#Foreground"></a>
    168 
    169 
    170 
    171 
    172 
    173 {@link
    174 android.app.Service#onStartCommand onStartCommand()} <a href="{@docRoot}guide/components/processes-and-threads.html"></a>
    175 
    176 </p>
    177 
    178 <p>
    179 </p>
    180 
    181 
    182 
    183 <h3 id="Declaring"></h3>
    184 
    185 <p> Activity
    186 </p>
    187 
    188 <p> <a href="{@docRoot}guide/topics/manifest/service-element.html">{@code &lt;service&gt;}</a>
    189  <a href="{@docRoot}guide/topics/manifest/application-element.html">{@code &lt;application&gt;}</a>
    190 </p>
    191 
    192 <pre>
    193 &lt;manifest ... &gt;
    194   ...
    195   &lt;application ... &gt;
    196       &lt;service android:name=".ExampleService" /&gt;
    197       ...
    198   &lt;/application&gt;
    199 &lt;/manifest&gt;
    200 </pre>
    201 
    202 <p>
    203 <a href="{@docRoot}guide/topics/manifest/service-element.html">{@code &lt;service&gt;}</a> </p>
    204 
    205 <p>
    206 <a href="{@docRoot}guide/topics/manifest/service-element.html">{@code &lt;service&gt;}</a>
    207 <a href="{@docRoot}guide/topics/manifest/service-element.html#nm">{@code android:name}</a>
    208  Intent <a href="http://android-developers.blogspot.com/2011/06/things-that-cannot-change.html">Things That Cannot Change</a>[]
    209 
    210 
    211 
    212 
    213 <p><strong> Intent  {@link android.app.Service}</strong> Intent 
    214  Intent 
    215 {@link
    216 android.content.Intent}
    217  {@link
    218 android.content.Intent#setPackage setPackage()}
    219   Intent </p>
    220 
    221 <p>
    222 <a href="{@docRoot}guide/topics/manifest/service-element.html#exported">{@code android:exported}</a>
    223  {@code "false"} Intent 
    224 </p>
    225 
    226 
    227 
    228 
    229 <h2 id="CreatingStartedService"></h2>
    230 
    231 <p> {@link
    232 android.content.Context#startService startService()} 
    233 {@link android.app.Service#onStartCommand onStartCommand()} </p>
    234 
    235 <p>
    236 
    237 
    238 {@link android.app.Service#stopSelf stopSelf()} 
    239 {@link android.content.Context#stopService stopService()} </p>
    240 
    241 <p> Activity {@link
    242 android.content.Context#startService startService()}  {@link android.content.Intent} 
    243 
    244 {@link android.app.Service#onStartCommand
    245 onStartCommand()}  {@link android.content.Intent}</p>
    246 
    247 <p> Activity  Activity 
    248 {@link
    249 android.content.Context#startService startService()}  Intent
    250 {@link
    251 android.app.Service#onStartCommand onStartCommand()}  Intent Internet 
    252 </p>
    253 
    254 <p class="caution"><strong></strong>
    255  Activity  Activity 
    256 
    257 
    258 </p>
    259 
    260 <p></p>
    261 <dl>
    262   <dt>{@link android.app.Service}</dt>
    263   <dd> Activity 
    264 
    265 
    266 </dd>
    267   <dt>{@link android.app.IntentService}</dt>
    268   <dd>
    269 {@link android.app.Service} 
    270  {@link
    271 android.app.IntentService#onHandleIntent onHandleIntent()}
    272  Intent</dd>
    273 </dl>
    274 
    275 <p>
    276 </p>
    277 
    278 
    279 <h3 id="ExtendingIntentService"> IntentService </h3>
    280 
    281 <p>
    282 {@link android.app.IntentService}
    283 </p>
    284 
    285 <p>{@link android.app.IntentService} </p>
    286 
    287 <ul>
    288   <li> {@link
    289 android.app.Service#onStartCommand onStartCommand()}
    290  Intent</li>
    291   <li> Intent  {@link
    292 android.app.IntentService#onHandleIntent onHandleIntent()}
    293 </li>
    294   <li>
    295 {@link android.app.Service#stopSelf}</li>
    296   <li>
    297 {@link android.app.IntentService#onBind onBind()}  null</li>
    298   <li> {@link android.app.IntentService#onStartCommand
    299 onStartCommand()}  Intent  {@link
    300 android.app.IntentService#onHandleIntent onHandleIntent()} </li>
    301 </ul>
    302 
    303 <p>
    304 {@link
    305 android.app.IntentService#onHandleIntent onHandleIntent()} </p>
    306 
    307 <p> {@link android.app.IntentService} </p>
    308 
    309 <pre>
    310 public class HelloIntentService extends IntentService {
    311 
    312   /**
    313    * A constructor is required, and must call the super {@link android.app.IntentService#IntentService}
    314    * constructor with a name for the worker thread.
    315    */
    316   public HelloIntentService() {
    317       super("HelloIntentService");
    318   }
    319 
    320   /**
    321    * The IntentService calls this method from the default worker thread with
    322    * the intent that started the service. When this method returns, IntentService
    323    * stops the service, as appropriate.
    324    */
    325   &#64;Override
    326   protected void onHandleIntent(Intent intent) {
    327       // Normally we would do some work here, like download a file.
    328       // For our sample, we just sleep for 5 seconds.
    329       long endTime = System.currentTimeMillis() + 5*1000;
    330       while (System.currentTimeMillis() &lt; endTime) {
    331           synchronized (this) {
    332               try {
    333                   wait(endTime - System.currentTimeMillis());
    334               } catch (Exception e) {
    335               }
    336           }
    337       }
    338   }
    339 }
    340 </pre>
    341 
    342 <p> {@link
    343 android.app.IntentService#onHandleIntent onHandleIntent()} </p>
    344 
    345 <p> {@link
    346 android.app.IntentService#onCreate onCreate()}{@link
    347 android.app.IntentService#onStartCommand onStartCommand()}  {@link
    348 android.app.IntentService#onDestroy onDestroy()}
    349 {@link android.app.IntentService} </p>
    350 
    351 <p>{@link android.app.IntentService#onStartCommand onStartCommand()}
    352  Intent  {@link
    353 android.app.IntentService#onHandleIntent onHandleIntent()}</p>
    354 
    355 <pre>
    356 &#64;Override
    357 public int onStartCommand(Intent intent, int flags, int startId) {
    358     Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
    359     return super.onStartCommand(intent,flags,startId);
    360 }
    361 </pre>
    362 
    363 <p>
    364 {@link android.app.IntentService#onHandleIntent onHandleIntent()}  {@link android.app.IntentService#onBind
    365 onBind()}</p>
    366 
    367 <p>
    368 {@link android.app.Service}
    369 </p>
    370 
    371 
    372 <h3 id="ExtendingService"></h3>
    373 
    374 <p>
    375 {@link android.app.IntentService} 
    376 {@link android.app.Service}
    377  Intent</p>
    378 
    379 <p> {@link
    380 android.app.Service}  {@link
    381 android.app.IntentService} 
    382 </p>
    383 
    384 <pre>
    385 public class HelloService extends Service {
    386   private Looper mServiceLooper;
    387   private ServiceHandler mServiceHandler;
    388 
    389   // Handler that receives messages from the thread
    390   private final class ServiceHandler extends Handler {
    391       public ServiceHandler(Looper looper) {
    392           super(looper);
    393       }
    394       &#64;Override
    395       public void handleMessage(Message msg) {
    396           // Normally we would do some work here, like download a file.
    397           // For our sample, we just sleep for 5 seconds.
    398           long endTime = System.currentTimeMillis() + 5*1000;
    399           while (System.currentTimeMillis() &lt; endTime) {
    400               synchronized (this) {
    401                   try {
    402                       wait(endTime - System.currentTimeMillis());
    403                   } catch (Exception e) {
    404                   }
    405               }
    406           }
    407           // Stop the service using the startId, so that we don't stop
    408           // the service in the middle of handling another job
    409           stopSelf(msg.arg1);
    410       }
    411   }
    412 
    413   &#64;Override
    414   public void onCreate() {
    415     // Start up the thread running the service.  Note that we create a
    416     // separate thread because the service normally runs in the process's
    417     // main thread, which we don't want to block.  We also make it
    418     // background priority so CPU-intensive work will not disrupt our UI.
    419     HandlerThread thread = new HandlerThread("ServiceStartArguments",
    420             Process.THREAD_PRIORITY_BACKGROUND);
    421     thread.start();
    422 
    423     // Get the HandlerThread's Looper and use it for our Handler
    424     mServiceLooper = thread.getLooper();
    425     mServiceHandler = new ServiceHandler(mServiceLooper);
    426   }
    427 
    428   &#64;Override
    429   public int onStartCommand(Intent intent, int flags, int startId) {
    430       Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
    431 
    432       // For each start request, send a message to start a job and deliver the
    433       // start ID so we know which request we're stopping when we finish the job
    434       Message msg = mServiceHandler.obtainMessage();
    435       msg.arg1 = startId;
    436       mServiceHandler.sendMessage(msg);
    437 
    438       // If we get killed, after returning from here, restart
    439       return START_STICKY;
    440   }
    441 
    442   &#64;Override
    443   public IBinder onBind(Intent intent) {
    444       // We don't provide binding, so return null
    445       return null;
    446   }
    447 
    448   &#64;Override
    449   public void onDestroy() {
    450     Toast.makeText(this, "service done", Toast.LENGTH_SHORT).show();
    451   }
    452 }
    453 </pre>
    454 
    455 <p> {@link android.app.IntentService} </p>
    456 
    457 <p> {@link android.app.Service#onStartCommand
    458 onStartCommand()} 
    459 
    460 </p>
    461 
    462 <p>{@link android.app.Service#onStartCommand onStartCommand()}
    463 {@link
    464 android.app.IntentService}
    465 
    466 {@link android.app.Service#onStartCommand onStartCommand()}
    467 </p>
    468 
    469 <dl>
    470   <dt>{@link android.app.Service#START_NOT_STICKY}</dt>
    471     <dd>
    472 {@link android.app.Service#onStartCommand
    473 onStartCommand()}  Intent <em></em>
    474 </dd>
    475   <dt>{@link android.app.Service#START_STICKY}</dt>
    476     <dd>
    477 {@link android.app.Service#onStartCommand
    478 onStartCommand()} 
    479 {@link
    480 android.app.Service#onStartCommand onStartCommand()} Intent Intent  Intent  Intent 
    481 {@link android.app.Service#onStartCommand onStartCommand()}<em></em>
    482 </dd>
    483   <dt>{@link android.app.Service#START_REDELIVER_INTENT}</dt>
    484     <dd> {@link android.app.Service#onStartCommand
    485 onStartCommand()}  Intent 
    486 {@link
    487 android.app.Service#onStartCommand onStartCommand()} Intent 
    488 </dd>
    489 </dl>
    490 <p>
    491 </p>
    492 
    493 
    494 
    495 <h3 id="StartingAService"></h3>
    496 
    497 <p>
    498 {@link android.content.Intent} {@link
    499 android.content.Context#startService startService()} Activity Android  {@link
    500 android.app.Service#onStartCommand onStartCommand()}  {@link
    501 android.content.Intent} {@link android.app.Service#onStartCommand
    502 onStartCommand()}</p>
    503 
    504 <p>Activity  Intent  {@link android.content.Context#startService
    505 startService()} ({@code
    506 HelloSevice})</p>
    507 
    508 <pre>
    509 Intent intent = new Intent(this, HelloService.class);
    510 startService(intent);
    511 </pre>
    512 
    513 <p>{@link android.content.Context#startService startService()} 
    514 Android  {@link android.app.Service#onStartCommand
    515 onStartCommand()}  {@link
    516 android.app.Service#onCreate onCreate()} {@link android.app.Service#onStartCommand
    517 onStartCommand()}</p>
    518 
    519 <p>
    520 {@link
    521 android.content.Context#startService startService()}  Intent 
    522 {@link android.app.PendingIntent}
    523  {@link android.app.PendingIntent#getBroadcast getBroadcast()}
    524 {@link android.content.Intent} 
    525 </p>
    526 
    527 <p>
    528 {@link android.app.Service#onStartCommand onStartCommand()} 
    529 {@link android.app.Service#stopSelf stopSelf()}  {@link
    530 android.content.Context#stopService stopService()}</p>
    531 
    532 
    533 <h3 id="Stopping"></h3>
    534 
    535 <p>
    536 {@link android.app.Service#onStartCommand onStartCommand()}
    537 
    538 {@link android.app.Service#stopSelf stopSelf()} 
    539 {@link android.content.Context#stopService stopService()} </p>
    540 
    541 <p> {@link android.app.Service#stopSelf stopSelf()}
    542  {@link
    543 android.content.Context#stopService stopService()} </p>
    544 
    545 <p>
    546 {@link
    547 android.app.Service#onStartCommand onStartCommand()}
    548 
    549 {@link android.app.Service#stopSelf(int)}
    550  {@link
    551 android.app.Service#stopSelf(int)}  ID  ID {@link android.app.Service#onStartCommand onStartCommand()}
    552  <code>startId</code>
    553  {@link
    554 android.app.Service#stopSelf(int)}  ID </p>
    555 
    556 <p class="caution"><strong></strong>
    557 
    558 {@link
    559 android.content.Context#stopService stopService()} 
    560 {@link
    561 android.app.Service#onStartCommand onStartCommand()} </p>
    562 
    563 <p><a href="#Lifecycle"></a></p>
    564 
    565 
    566 
    567 <h2 id="CreatingBoundService"></h2>
    568 
    569 <p> {@link
    570 android.content.Context#bindService bindService()} 
    571 {@link
    572 android.content.Context#startService startService()} <em></em></p>
    573 
    574 <p> Activity  (IPC) 
    575 
    576 </p>
    577 
    578 <p>
    579 {@link
    580 android.app.Service#onBind onBind()}  {@link android.os.IBinder}
    581 {@link android.content.Context#bindService bindService()}
    582 
    583 {@link android.app.Service#onStartCommand onStartCommand()}
    584 
    585 <em></em></p>
    586 
    587 <p>
    588 
    589 {@link android.os.IBinder} 
    590 {@link android.app.Service#onBind
    591 onBind()} 
    592 {@link android.os.IBinder}</p>
    593 
    594 <p>
    595 {@link android.content.Context#unbindService unbindService()} 
    596 </p>
    597 
    598 <p><a href="{@docRoot}guide/components/bound-services.html"></a>
    599 
    600 </p>
    601 
    602 
    603 
    604 <h2 id="Notifications"></h2>
    605 
    606 <p> <a href="{@docRoot}guide/topics/ui/notifiers/toasts.html">Toast </a><a href="{@docRoot}guide/topics/ui/notifiers/notifications.html"></a></p>
    607 
    608 <p>Toast  Activity
    609 
    610 </p>
    611 
    612 <p>
    613 
    614  Activity
    615 </p>
    616 
    617 <p>
    618 <a href="{@docRoot}guide/topics/ui/notifiers/toasts.html">Toast </a><a href="{@docRoot}guide/topics/ui/notifiers/notifications.html"></a></p>
    619 
    620 
    621 
    622 <h2 id="Foreground"></h2>
    623 
    624 <p>
    625 
    626 
    627 
    628 </p>
    629 
    630 <p>
    631 
    632  Activity 
    633 </p>
    634 
    635 <p> {@link
    636 android.app.Service#startForeground startForeground()}
    637 {@link
    638 android.app.Notification}</p>
    639 
    640 <pre>
    641 Notification notification = new Notification(R.drawable.icon, getText(R.string.ticker_text),
    642         System.currentTimeMillis());
    643 Intent notificationIntent = new Intent(this, ExampleActivity.class);
    644 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    645 notification.setLatestEventInfo(this, getText(R.string.notification_title),
    646         getText(R.string.notification_message), pendingIntent);
    647 startForeground(ONGOING_NOTIFICATION_ID, notification);
    648 </pre>
    649 
    650 <p class="caution"><strong></strong> {@link
    651 android.app.Service#startForeground startForeground()}  ID  0</p>
    652 
    653 
    654 <p>
    655 {@link android.app.Service#stopForeground stopForeground()}
    656 
    657 <em></em>
    658 </p>
    659 
    660 <p><a href="{@docRoot}guide/topics/ui/notifiers/notifications.html"></a>
    661 </p>
    662 
    663 
    664 
    665 <h2 id="Lifecycle"></h2>
    666 
    667 <p> Activity 
    668 
    669 </p>
    670 
    671 <p>
    672 </p>
    673 
    674 <ul>
    675 <li>
    676   <p> {@link
    677 android.content.Context#startService startService()} 
    678 {@link
    679 android.app.Service#stopSelf() stopSelf()} 
    680 {@link android.content.Context#stopService
    681 stopService()} </p></li>
    682 
    683 <li>
    684   <p> {@link
    685 android.content.Context#bindService bindService()} 
    686 {@link android.os.IBinder} 
    687 {@link android.content.Context#unbindService unbindService()} 
    688 
    689 <em></em></p></li>
    690 </ul>
    691 
    692 <p>
    693 {@link android.content.Context#startService startService()} 
    694 {@link android.content.Intent} {@link android.content.Context#startService
    695 startService()} Activity 
    696 {@link
    697 android.content.Context#bindService bindService()}
    698  {@link
    699 android.content.Context#stopService stopService()}  {@link android.app.Service#stopSelf
    700 stopSelf()}  </p>
    701 
    702 
    703 <h3 id="LifecycleCallbacks"></h3>
    704 
    705 <p> Activity 
    706 
    707 </p>
    708 
    709 <pre>
    710 public class ExampleService extends Service {
    711     int mStartMode;       // indicates how to behave if the service is killed
    712     IBinder mBinder;      // interface for clients that bind
    713     boolean mAllowRebind; // indicates whether onRebind should be used
    714 
    715     &#64;Override
    716     public void {@link android.app.Service#onCreate onCreate}() {
    717         // The service is being created
    718     }
    719     &#64;Override
    720     public int {@link android.app.Service#onStartCommand onStartCommand}(Intent intent, int flags, int startId) {
    721         // The service is starting, due to a call to {@link android.content.Context#startService startService()}
    722         return <em>mStartMode</em>;
    723     }
    724     &#64;Override
    725     public IBinder {@link android.app.Service#onBind onBind}(Intent intent) {
    726         // A client is binding to the service with {@link android.content.Context#bindService bindService()}
    727         return <em>mBinder</em>;
    728     }
    729     &#64;Override
    730     public boolean {@link android.app.Service#onUnbind onUnbind}(Intent intent) {
    731         // All clients have unbound with {@link android.content.Context#unbindService unbindService()}
    732         return <em>mAllowRebind</em>;
    733     }
    734     &#64;Override
    735     public void {@link android.app.Service#onRebind onRebind}(Intent intent) {
    736         // A client is binding to the service with {@link android.content.Context#bindService bindService()},
    737         // after onUnbind() has already been called
    738     }
    739     &#64;Override
    740     public void {@link android.app.Service#onDestroy onDestroy}() {
    741         // The service is no longer used and is being destroyed
    742     }
    743 }
    744 </pre>
    745 
    746 <p class="note"><strong></strong> Activity 
    747 <em></em></p>
    748 
    749 <img src="{@docRoot}images/service_lifecycle.png" alt="" />
    750 <p class="img-caption"><strong> 2. </strong>
    751 {@link android.content.Context#startService
    752 startService()} 
    753 {@link android.content.Context#bindService bindService()} </p>
    754 
    755 <p> </p>
    756 
    757 <ul>
    758 <li><strong></strong> {@link
    759 android.app.Service#onCreate onCreate()}  {@link
    760 android.app.Service#onDestroy}  Activity 
    761 {@link android.app.Service#onCreate onCreate()}  {@link
    762 android.app.Service#onDestroy onDestroy()}  {@link
    763 android.app.Service#onCreate onCreate()}  {@link
    764 android.app.Service#onDestroy onDestroy()} 
    765 
    766 
    767 <p> {@link android.content.Context#startService startService()}
    768  {@link
    769 android.content.Context#bindService bindService()}  {@link android.app.Service#onCreate onCreate()}  {@link android.app.Service#onDestroy
    770 onDestroy()} </p></li>
    771 
    772 <li><strong></strong> {@link
    773 android.app.Service#onStartCommand onStartCommand()}  {@link android.app.Service#onBind onBind()}
    774  {@link
    775 android.content.Intent}  {@link android.content.Context#startService
    776 startService()}  {@link android.content.Context#bindService bindService()}
    777 <p>
    778 {@link android.app.Service#onStartCommand
    779 onStartCommand()}  {@link
    780 android.app.Service#onUnbind onUnbind()} </p>
    781 </li>
    782 </ul>
    783 
    784 <p class="note"><strong></strong>
    785 {@link android.app.Service#stopSelf stopSelf()}  {@link
    786 android.content.Context#stopService stopService()}  {@code onStop()}
    787 &mdash;{@link
    788 android.app.Service#onDestroy onDestroy()} 
    789 </p>
    790 
    791 <p> 2 
    792 {@link android.content.Context#startService startService()} 
    793 {@link android.content.Context#bindService bindService()}
    794 
    795 {@link android.app.Service#onStartCommand
    796 onStartCommand()} {@link android.content.Context#startService startService()}
    797 {@link android.app.Service#onBind onBind()} 
    798 {@link android.content.Context#bindService bindService()} </p>
    799 
    800 <p><a href="{@docRoot}guide/components/bound-services.html"></a><a href="{@docRoot}guide/components/bound-services.html#Lifecycle"></a>
    801 {@link android.app.Service#onRebind onRebind()}
    802 
    803 </p>
    804 
    805 
    806 <!--
    807 <h2>Beginner's Path</h2>
    808 
    809 <p>To learn how to query data from the system or other applications (such as contacts or media
    810 stored on the device), continue with the <b><a
    811 href="{@docRoot}guide/topics/providers/content-providers.html">Content Providers</a></b>
    812 document.</p>
    813 -->
    814