Lines Matching full:link
40 <li>{@link android.app.Service}</li>
41 <li>{@link android.app.IntentService}</li>
60 <p>A {@link android.app.Service} is an application component that can perform
73 calling {@link android.content.Context#startService startService()}. Once started, a service
79 <dd>A service is "bound" when an application component binds to it by calling {@link
89 It's simply a matter of whether you implement a couple callback methods: {@link
90 android.app.Service#onStartCommand onStartCommand()} to allow components to start it and {@link
95 an activity—by starting it with an {@link android.content.Intent}. However, you can declare
120 a thread in {@link android.app.Activity#onCreate onCreate()}, start running it in {@link
121 android.app.Activity#onStart onStart()}, then stop it in {@link android.app.Activity#onStop
122 onStop()}. Also consider using {@link android.os.AsyncTask} or {@link android.os.HandlerThread},
123 instead of the traditional {@link java.lang.Thread} class. See the <a
132 <p>To create a service, you must create a subclass of {@link android.app.Service} (or one
138 <dt>{@link android.app.Service#onStartCommand onStartCommand()}</dt>
140 requests that the service be started, by calling {@link android.content.Context#startService
143 its work is done, by calling {@link android.app.Service#stopSelf stopSelf()} or {@link
146 <dt>{@link android.app.Service#onBind onBind()}</dt>
148 service (such as to perform RPC), by calling {@link android.content.Context#bindService
150 use to communicate with the service, by returning an {@link android.os.IBinder}. You must always
152 <dt>{@link android.app.Service#onCreate()}</dt>
154 procedures (before it calls either {@link android.app.Service#onStartCommand onStartCommand()} or
155 {@link android.app.Service#onBind onBind()}). If the service is already running, this method is not
157 <dt>{@link android.app.Service#onDestroy()}</dt>
163 <p>If a component starts the service by calling {@link
164 android.content.Context#startService startService()} (which results in a call to {@link
166 remains running until it stops itself with {@link android.app.Service#stopSelf()} or another
167 component stops it by calling {@link android.content.Context#stopService stopService()}.</p>
170 {@link android.content.Context#bindService bindService()} to create the service (and {@link
183 available again (though this also depends on the value you return from {@link
233 service declares an intent filter that matches the intent another application passes to {@link
255 <p>A started service is one that another component starts by calling {@link
257 {@link android.app.Service#onStartCommand onStartCommand()} method.</p>
262 is done by calling {@link android.app.Service#stopSelf stopSelf()}, or another component can stop it
263 by calling {@link android.content.Context#stopService stopService()}.</p>
265 <p>An application component such as an activity can start the service by calling {@link
266 android.content.Context#startService startService()} and passing an {@link android.content.Intent}
268 this {@link android.content.Intent} in the {@link android.app.Service#onStartCommand
272 start a companion service and deliver it the data to save by passing an intent to {@link
273 android.content.Context#startService startService()}. The service receives the intent in {@link
286 <dt>{@link android.app.Service}</dt>
291 <dt>{@link android.app.IntentService}</dt>
292 <dd>This is a subclass of {@link android.app.Service} that uses a worker thread to handle all
294 handle multiple requests simultaneously. All you need to do is implement {@link
307 implement your service using the {@link android.app.IntentService} class.</p>
309 <p>The {@link android.app.IntentService} does the following:</p>
312 <li>Creates a default worker thread that executes all intents delivered to {@link
315 <li>Creates a work queue that passes one intent at a time to your {@link
319 {@link android.app.Service#stopSelf}.</li>
320 <li>Provides default implementation of {@link android.app.IntentService#onBind onBind()} that
322 <li>Provides a default implementation of {@link android.app.IntentService#onStartCommand
323 onStartCommand()} that sends the intent to the work queue and then to your {@link
327 <p>All this adds up to the fact that all you need to do is implement {@link
331 <p>Here's an example implementation of {@link android.app.IntentService}:</p>
337 * A constructor is required, and must call the super {@link android.app.IntentService#IntentService}
366 <p>That's all you need: a constructor and an implementation of {@link
369 <p>If you decide to also override other callback methods, such as {@link
370 android.app.IntentService#onCreate onCreate()}, {@link
371 android.app.IntentService#onStartCommand onStartCommand()}, or {@link
373 that the {@link android.app.IntentService} can properly handle the life of the worker thread.</p>
375 <p>For example, {@link android.app.IntentService#onStartCommand onStartCommand()} must return
376 the default implementation (which is how the intent gets delivered to {@link
387 <p>Besides {@link android.app.IntentService#onHandleIntent onHandleIntent()}, the only method
388 from which you don't need to call the super class is {@link android.app.IntentService#onBind
392 the base {@link android.app.Service} class, which is a lot more code, but which might be
398 <p>As you saw in the previous section, using {@link android.app.IntentService} makes your
401 can extend the {@link android.app.Service} class to handle each intent.</p>
403 <p>For comparison, the following example code is an implementation of the {@link
404 android.app.Service} class that performs the exact same work as the example above using {@link
479 <p>As you can see, it's a lot more work than using {@link android.app.IntentService}.</p>
481 <p>However, because you handle each call to {@link android.app.Service#onStartCommand
486 <p>Notice that the {@link android.app.Service#onStartCommand onStartCommand()} method must return an
488 event that the system kills it (as discussed above, the default implementation for {@link
490 from {@link android.app.Service#onStartCommand onStartCommand()} must be one of the following
494 <dt>{@link android.app.Service#START_NOT_STICKY}</dt>
495 <dd>If the system kills the service after {@link android.app.Service#onStartCommand
499 <dt>{@link android.app.Service#START_STICKY}</dt>
500 <dd>If the system kills the service after {@link android.app.Service#onStartCommand
501 onStartCommand()} returns, recreate the service and call {@link
503 Instead, the system calls {@link android.app.Service#onStartCommand onStartCommand()} with a
507 <dt>{@link android.app.Service#START_REDELIVER_INTENT}</dt>
508 <dd>If the system kills the service after {@link android.app.Service#onStartCommand
509 onStartCommand()} returns, recreate the service and call {@link
522 {@link android.content.Intent} (specifying the service to start) to {@link
523 android.content.Context#startService startService()}. The Android system calls the service's {@link
524 android.app.Service#onStartCommand onStartCommand()} method and passes it the {@link
525 android.content.Intent}. (You should never call {@link android.app.Service#onStartCommand
529 HelloSevice}) using an explicit intent with {@link android.content.Context#startService
537 <p>The {@link android.content.Context#startService startService()} method returns immediately and
538 the Android system calls the service's {@link android.app.Service#onStartCommand
539 onStartCommand()} method. If the service is not already running, the system first calls {@link
540 android.app.Service#onCreate onCreate()}, then calls {@link android.app.Service#onStartCommand
543 <p>If the service does not also provide binding, the intent delivered with {@link
546 the client that starts the service can create a {@link android.app.PendingIntent} for a broadcast
547 (with {@link android.app.PendingIntent#getBroadcast getBroadcast()}) and deliver it to the service
548 in the {@link android.content.Intent} that starts the service. The service can then use the
552 {@link android.app.Service#onStartCommand onStartCommand()}. However, only one request to stop
553 the service (with {@link android.app.Service#stopSelf stopSelf()} or {@link
561 continues to run after {@link android.app.Service#onStartCommand onStartCommand()} returns. So,
562 the service must stop itself by calling {@link android.app.Service#stopSelf stopSelf()} or another
563 component can stop it by calling {@link android.content.Context#stopService stopService()}.</p>
565 <p>Once requested to stop with {@link android.app.Service#stopSelf stopSelf()} or {@link
569 <p>However, if your service handles multiple requests to {@link
573 this problem, you can use {@link android.app.Service#stopSelf(int)} to ensure that your request to
574 stop the service is always based on the most recent start request. That is, when you call {@link
576 delivered to {@link android.app.Service#onStartCommand onStartCommand()}) to which your stop request
577 corresponds. Then if the service received a new start request before you were able to call {@link
582 other components can stop the service by calling {@link
584 you must always stop the service yourself if it ever received a call to {@link
594 <p>A bound service is one that allows application components to bind to it by calling {@link
596 (and generally does not allow components to <em>start</em> it by calling {@link
603 <p>To create a bound service, you must implement the {@link
604 android.app.Service#onBind onBind()} callback method to return an {@link android.os.IBinder} that
606 {@link android.content.Context#bindService bindService()} to retrieve the interface and
610 through {@link android.app.Service#onStartCommand onStartCommand()}).</p>
614 link android.os.IBinder} and is what your service must
615 return from the {@link android.app.Service#onBind
616 onBind()} callback method. Once the client receives the {@link android.os.IBinder}, it can begin
620 service, it calls {@link android.content.Context#unbindService unbindService()} to unbind. Once
665 <p>To request that your service run in the foreground, call {@link
667 that uniquely identifies the notification and the {@link
680 <p class="caution"><strong>Caution:</strong> The integer ID you give to {@link
684 <p>To remove the service from the foreground, call {@link
707 <p>The service is created when another component calls {@link
709 stop itself by calling {@link
711 service by calling {@link android.content.Context#stopService
715 <p>The service is created when another component (a client) calls {@link
717 through an {@link android.os.IBinder} interface. The client can close the connection by calling
718 {@link android.content.Context#unbindService unbindService()}. Multiple clients can bind to
724 started with {@link android.content.Context#startService startService()}. For example, a background
725 music service could be started by calling {@link android.content.Context#startService
726 startService()} with an {@link android.content.Intent} that identifies the music to play. Later,
728 current song, an activity can bind to the service by calling {@link
729 android.content.Context#bindService bindService()}. In cases like this, {@link
730 android.content.Context#stopService stopService()} or {@link android.app.Service#stopSelf
747 public void {@link android.app.Service#onCreate onCreate}() {
751 public int {@link android.app.Service#onStartCommand onStartCommand}(Intent intent, int flags, int startId) {
752 // The service is starting, due to a call to {@link android.content.Context#startService startService()}
756 public IBinder {@link android.app.Service#onBind onBind}(Intent intent) {
757 // A client is binding to the service with {@link android.content.Context#bindService bindService()}
761 public boolean {@link android.app.Service#onUnbind onUnbind}(Intent intent) {
762 // All clients have unbound with {@link android.content.Context#unbindService unbindService()}
766 public void {@link android.app.Service#onRebind onRebind}(Intent intent) {
767 // A client is binding to the service with {@link android.content.Context#bindService bindService()},
771 public void {@link android.app.Service#onDestroy onDestroy}() {
782 shows the lifecycle when the service is created with {@link android.content.Context#startService
784 with {@link android.content.Context#bindService bindService()}.</p>
789 <li>The <strong>entire lifetime</strong> of a service happens between the time {@link
790 android.app.Service#onCreate onCreate()} is called and the time {@link
792 {@link android.app.Service#onCreate onCreate()} and releases all remaining resources in {@link
794 music playback service could create the thread where the music will be played in {@link
795 android.app.Service#onCreate onCreate()}, then stop the thread in {@link
798 <p>The {@link android.app.Service#onCreate onCreate()} and {@link android.app.Service#onDestroy
800 they're created by {@link android.content.Context#startService startService()} or {@link
803 <li>The <strong>active lifetime</strong> of a service begins with a call to either {@link
804 android.app.Service#onStartCommand onStartCommand()} or {@link android.app.Service#onBind onBind()}.
805 Each method is handed the {@link
806 android.content.Intent} that was passed to either {@link android.content.Context#startService
807 startService()} or {@link android.content.Context#bindService bindService()}, respectively.
809 ends (the service is still active even after {@link android.app.Service#onStartCommand
810 onStartCommand()} returns). If the service is bound, the active lifetime ends when {@link
816 either {@link android.app.Service#stopSelf stopSelf()} or {@link
819 the system destroys it when the service is stopped—{@link
823 services that are created by {@link android.content.Context#startService startService()} from those
824 created by {@link android.content.Context#bindService bindService()}, keep
826 So, a service that was initially started with {@link android.app.Service#onStartCommand
827 onStartCommand()} (by a client calling {@link android.content.Context#startService startService()})
828 can still receive a call to {@link android.app.Service#onBind onBind()} (when a client calls
829 {@link android.content.Context#bindService bindService()}).</p>
833 which includes more information about the {@link android.app.Service#onRebind onRebind()}