Home | History | Annotate | Download | only in app

Lines Matching defs:Service

34  * A Service is an application component representing either an application's desire
36 * or to supply functionality for other applications to use. Each service
38 * {@link android.R.styleable#AndroidManifestService <service>}
45 * thread of their hosting process. This means that, if your service is going
51 * as a standard implementation of Service that has its own thread where it
54 * <p>The Service class is an important part of an
59 * <li><a href="#WhatIsAService">What is a Service?</a>
60 * <li><a href="#ServiceLifecycle">Service Lifecycle</a>
63 * <li><a href="#LocalServiceSample">Local Service Sample</a>
64 * <li><a href="#RemoteMessengerServiceSample">Remote Messenger Service Sample</a>
68 * <h3>What is a Service?</h3>
70 * <p>Most confusion about the Service class actually revolves around what
74 * <li> A Service is <b>not</b> a separate process. The Service object itself
77 * <li> A Service is <b>not</b> a thread. It is not a means itself to do work off
81 * <p>Thus a Service itself is actually very simple, providing two main features:</p>
88 * ask the system to schedule work for the service, to be run until the service
93 * allows a long-standing connection to be made to the service in order to
97 * <p>When a Service component is actually created, for either of these reasons,
100 * main thread. It is up to the Service to implement these with the appropriate
103 * <p>Note that because Service itself is so simple, you can make your
106 * by <a href="#LocalServiceSample">Local Service Sample</a>), to providing
110 * <h3>Service Lifecycle</h3>
112 * <p>There are two reasons that a service can be run by the system. If someone
114 * retrieve the service (creating it and calling its {@link #onCreate} method
116 * arguments supplied by the client. The service will at this point continue
120 * calls to onStartCommand()), so no matter how many times it is started a service
122 * services can use their {@link #stopSelf(int)} method to ensure the service is
134 * obtain a persistent connection to a service. This likewise creates the
135 * service if it is not already running (calling {@link #onCreate} while
137 * {@link android.os.IBinder} object that the service returns from its
139 * to the service. The service will remain running as long as the connection
141 * service's IBinder). Usually the IBinder returned is for a complex
145 * <p>A service can be both started and have connections bound to it. In such
146 * a case, the system will keep the service running as long as either it is
150 * of these situations hold, the service's {@link #onDestroy} method is called
151 * and the service is effectively terminated. All cleanup (stopping threads,
157 * <p>Global access to a service can be enforced when it is declared in its
158 * manifest's {@link android.R.styleable#AndroidManifestService &lt;service&gt;}
162 * the service.
164 * <p>In addition, a service can protect individual IPC calls into it with
175 * <p>The Android system will attempt to keep the process hosting a service
176 * around as long as the service has been started or has clients bound to it.
178 * priority of a process hosting the service will be the higher of the
182 * <li><p>If the service is currently executing code in its
187 * <li><p>If the service has been started, then its hosting process is considered
191 * the service should not be killed except in extreme low memory conditions.
192 * <li><p>If there are clients bound to the service, then the service's hosting
194 * if one of its clients is visible to the user, then the service itself is
196 * <li><p>A started service can use the {@link #startForeground(int, Notification)}
197 * API to put the service in a foreground state, where the system considers
200 * the service to be killed under extreme memory pressure from the current
204 * <p>Note this means that most of the time your service is running, it may
206 * happens, the system will later try to restart the service. An important
210 * re-deliver an Intent for you so that it does not get lost if your service
213 * <p>Other application components running in the same process as the service
216 * process beyond just the importance of the service itself.
219 * <h3>Local Service Sample</h3>
221 * <p>One of the most common uses of a Service is as a secondary component
228 * between them: clients of the service can simply cast the IBinder they
229 * receive from it to a concrete class published by the service.
231 * <p>An example of this use of a Service is shown here. First is the Service
235 * service}
238 * running service, such as:
244 * <h3>Remote Messenger Service Sample</h3>
246 * <p>If you need to be able to write a Service that can perform complicated
252 * <p>An example of a Service that uses Messenger as its client interface
253 * is shown here. First is the Service itself, publishing a Messenger to
257 * service}
259 * <p>If we want to make this service run in a remote process (instead of the
269 * <p>With that done, clients can now bind to the service and send messages
276 public abstract class Service extends ContextWrapper implements ComponentCallbacks {
277 private static final String TAG = "Service";
279 public Service() {
283 /** Return the application that owns this service. */
289 * Called by the system when the service is first created. Do not call this method directly.
303 * the service if it is killed. May be {@link #START_STICKY},
317 * Constant to return from {@link #onStartCommand}: if this service's
321 * re-create the service. Because it is in the started state, it will
323 * service instance; if there are not any pending start commands to be
324 * delivered to the service, it will be called with a null intent
328 * and stopped to run for arbitrary periods of time, such as a service
334 * Constant to return from {@link #onStartCommand}: if this service's
337 * deliver to it, then take the service out of the started state and
340 * service will not receive a {@link #onStartCommand(Intent, int, int)}
347 * example of such a service would be one that polls for data from
349 * the alarm start its service. When its {@link #onStartCommand} is
352 * while doing that check, the service will not be restarted until the
358 * Constant to return from {@link #onStartCommand}: if this service's
363 * redelivery until the service calls {@link #stopSelf(int)} with the
365 * service will not receive a {@link #onStartCommand(Intent, int, int)}
374 * re-delivery of a previously delivered intent, because the service
388 * Called by the system every time a client explicitly starts the service by calling
405 * service's main thread. A service's main thread is the same
413 * as given. This may be null if the service is being restarted after
422 * use for the service's current started state. It may be one of the
433 * Called by the system to notify a Service that it is no longer used and is being removed. The
434 * service should clean up an resources it holds (threads, registered
436 * in to this Service object and it is effectively dead. Do not call this method directly.
448 * Return the communication channel to the service. May return null if
449 * clients can not bind to the service. The returned
460 * @param intent The Intent that was used to bind to this service,
466 * service.
472 * published by the service. The default implementation does nothing and
475 * @param intent The Intent that was used to bind to this service,
480 * @return Return true if you would like to have the service's
488 * Called when new clients have connected to the service, after it had
493 * @param intent The Intent that was used to bind to this service,
502 * Stop the service, if it was previously started. This is the same as
503 * calling {@link android.content.Context#stopService} for this particular service.
528 * Stop the service if the most recent time it was started was
530 * android.content.Context#stopService} for this particular service but allows you to
536 * you have called it for previously received IDs, the service will be
544 * and the service will be stopped, else false.
578 * Make this service run in the foreground, supplying the ongoing
583 * flag if killing your service would be disruptive to the user, such as
584 * if your service is performing background music playback, so the user
611 * Remove this service from foreground state, allowing it to be killed if
615 * until a later call removes it (or the service is destroyed).
628 * Print the Service's state into the given stream. This gets invoked if
629 * you run "adb shell dumpsys activity service <yourservicename>".
646 //Log.i("Service", "Finalizing Service: " + this);