public abstract class Service extends ContextWrapper implements ComponentCallbacks2
<service>
declaration in its package's AndroidManifest.xml
. Services
can be started with
Context.startService()
and
Context.bindService()
.
Note that services, like other application objects, run in the main
thread of their hosting process. This means that, if your service is going
to do any CPU intensive (such as MP3 playback) or blocking (such as
networking) operations, it should spawn its own thread in which to do that
work. More information on this can be found in
Processes and
Threads. The IntentService
class is available
as a standard implementation of Service that has its own thread where it
schedules its work to be done.
Topics covered here:
For a detailed discussion about how to create services, read the Services developer guide.
Most confusion about the Service class actually revolves around what it is not:
Thus a Service itself is actually very simple, providing two main features:
Context.startService()
, which
ask the system to schedule work for the service, to be run until the service
or someone else explicitly stop it.
Context.bindService()
, which
allows a long-standing connection to be made to the service in order to
interact with it.
When a Service component is actually created, for either of these reasons,
all that the system actually does is instantiate the component
and call its onCreate()
and any other appropriate callbacks on the
main thread. It is up to the Service to implement these with the appropriate
behavior, such as creating a secondary thread in which it does its work.
Note that because Service itself is so simple, you can make your interaction with it as simple or complicated as you want: from treating it as a local Java object that you make direct method calls on (as illustrated by Local Service Sample), to providing a full remoteable interface using AIDL.
There are two reasons that a service can be run by the system. If someone
calls Context.startService()
then the system will
retrieve the service (creating it and calling its onCreate()
method
if needed) and then call its onStartCommand(android.content.Intent, int, int)
method with the
arguments supplied by the client. The service will at this point continue
running until Context.stopService()
or
stopSelf()
is called. Note that multiple calls to
Context.startService() do not nest (though they do result in multiple corresponding
calls to onStartCommand()), so no matter how many times it is started a service
will be stopped once Context.stopService() or stopSelf() is called; however,
services can use their stopSelf(int)
method to ensure the service is
not stopped until started intents have been processed.
For started services, there are two additional major modes of operation
they can decide to run in, depending on the value they return from
onStartCommand(): START_STICKY
is used for services that are
explicitly started and stopped as needed, while START_NOT_STICKY
or START_REDELIVER_INTENT
are used for services that should only
remain running while processing any commands sent to them. See the linked
documentation for more detail on the semantics.
Clients can also use Context.bindService()
to
obtain a persistent connection to a service. This likewise creates the
service if it is not already running (calling onCreate()
while
doing so), but does not call onStartCommand(). The client will receive the
IBinder
object that the service returns from its
onBind(android.content.Intent)
method, allowing the client to then make calls back
to the service. The service will remain running as long as the connection
is established (whether or not the client retains a reference on the
service's IBinder). Usually the IBinder returned is for a complex
interface that has been written
in aidl.
A service can be both started and have connections bound to it. In such
a case, the system will keep the service running as long as either it is
started or there are one or more connections to it with the
Context.BIND_AUTO_CREATE
flag. Once neither
of these situations hold, the service's onDestroy()
method is called
and the service is effectively terminated. All cleanup (stopping threads,
unregistering receivers) should be complete upon returning from onDestroy().
Global access to a service can be enforced when it is declared in its
manifest's <service>
tag. By doing so, other applications will need to declare a corresponding
<uses-permission>
element in their own manifest to be able to start, stop, or bind to
the service.
As of Build.VERSION_CODES.GINGERBREAD
, when using
Context.startService(Intent)
, you can
also set Intent.FLAG_GRANT_READ_URI_PERMISSION
and/or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
on the Intent. This will grant the
Service temporary access to the specific URIs in the Intent. Access will
remain until the Service has called stopSelf(int)
for that start
command or a later one, or until the Service has been completely stopped.
This works for granting access to the other apps that have not requested
the permission protecting the Service, or even when the Service is not
exported at all.
In addition, a service can protect individual IPC calls into it with
permissions, by calling the
ContextWrapper.checkCallingPermission(java.lang.String)
method before executing the implementation of that call.
See the Security and Permissions document for more information on permissions and security in general.
The Android system will attempt to keep the process hosting a service around as long as the service has been started or has clients bound to it. When running low on memory and needing to kill existing processes, the priority of a process hosting the service will be the higher of the following possibilities:
If the service is currently executing code in its
onCreate()
, onStartCommand()
,
or onDestroy()
methods, then the hosting process will
be a foreground process to ensure this code can execute without
being killed.
If the service has been started, then its hosting process is considered to be less important than any processes that are currently visible to the user on-screen, but more important than any process not visible. Because only a few processes are generally visible to the user, this means that the service should not be killed except in extreme low memory conditions.
If there are clients bound to the service, then the service's hosting process is never less important than the most important client. That is, if one of its clients is visible to the user, then the service itself is considered to be visible.
A started service can use the startForeground(int, Notification)
API to put the service in a foreground state, where the system considers
it to be something the user is actively aware of and thus not a candidate
for killing when low on memory. (It is still theoretically possible for
the service to be killed under extreme memory pressure from the current
foreground application, but in practice this should not be a concern.)
Note this means that most of the time your service is running, it may
be killed by the system if it is under heavy memory pressure. If this
happens, the system will later try to restart the service. An important
consequence of this is that if you implement onStartCommand()
to schedule work to be done asynchronously or in another thread, then you
may want to use START_FLAG_REDELIVERY
to have the system
re-deliver an Intent for you so that it does not get lost if your service
is killed while processing it.
Other application components running in the same process as the service
(such as an Activity
) can, of course, increase the
importance of the overall
process beyond just the importance of the service itself.
One of the most common uses of a Service is as a secondary component running alongside other parts of an application, in the same process as the rest of the components. All components of an .apk run in the same process unless explicitly stated otherwise, so this is a typical situation.
When used in this way, by assuming the components are in the same process, you can greatly simplify the interaction between them: clients of the service can simply cast the IBinder they receive from it to a concrete class published by the service.
An example of this use of a Service is shown here. First is the Service itself, publishing a custom class when bound:
With that done, one can now write client code that directly accesses the running service, such as:
If you need to be able to write a Service that can perform complicated
communication with clients in remote processes (beyond simply the use of
Context.startService
to send
commands to it), then you can use the Messenger
class
instead of writing full AIDL files.
An example of a Service that uses Messenger as its client interface is shown here. First is the Service itself, publishing a Messenger to an internal Handler when bound:
If we want to make this service run in a remote process (instead of the
standard one for its .apk), we can use android:process
in its
manifest tag to specify one:
Note that the name "remote" chosen here is arbitrary, and you can use other names if you want additional processes. The ':' prefix appends the name to your package's standard process name.
With that done, clients can now bind to the service and send messages to it. Note that this allows clients to register with it to receive messages back as well:
Modifier and Type | Field and Description |
---|---|
static int |
START_CONTINUATION_MASK
Bits returned by
onStartCommand(android.content.Intent, int, int) describing how to continue
the service if it is killed. |
static int |
START_FLAG_REDELIVERY
This flag is set in
onStartCommand(android.content.Intent, int, int) if the Intent is a
re-delivery of a previously delivered intent, because the service
had previously returned START_REDELIVER_INTENT but had been
killed before calling stopSelf(int) for that Intent. |
static int |
START_FLAG_RETRY
This flag is set in
onStartCommand(android.content.Intent, int, int) if the Intent is a
a retry because the original attempt never got to or returned from
onStartCommand(Intent, int, int) . |
static int |
START_NOT_STICKY
Constant to return from
onStartCommand(android.content.Intent, int, int) : if this service's
process is killed while it is started (after returning from
onStartCommand(android.content.Intent, int, int) ), and there are no new start intents to
deliver to it, then take the service out of the started state and
don't recreate until a future explicit call to
Context.startService(Intent) . |
static int |
START_REDELIVER_INTENT
Constant to return from
onStartCommand(android.content.Intent, int, int) : if this service's
process is killed while it is started (after returning from
onStartCommand(android.content.Intent, int, int) ), then it will be scheduled for a restart
and the last delivered Intent re-delivered to it again via
onStartCommand(android.content.Intent, int, int) . |
static int |
START_STICKY
Constant to return from
onStartCommand(android.content.Intent, int, int) : if this service's
process is killed while it is started (after returning from
onStartCommand(android.content.Intent, int, int) ), then leave it in the started state but
don't retain this delivered intent. |
static int |
START_STICKY_COMPATIBILITY
Constant to return from
onStartCommand(android.content.Intent, int, int) : compatibility
version of START_STICKY that does not guarantee that
onStartCommand(android.content.Intent, int, int) will be called again after being killed. |
static int |
START_TASK_REMOVED_COMPLETE
Special constant for reporting that we are done processing
onTaskRemoved(Intent) . |
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BACKUP_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_VISIBLE, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, COUNTRY_DETECTOR, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_ROUTER_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_POLICY_SERVICE, NETWORK_STATS_SERVICE, NETWORKMANAGEMENT_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, SCHEDULING_POLICY_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SERIAL_SERVICE, SIP_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, TELEPHONY_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, THROTTLE_SERVICE, UI_MODE_SERVICE, UPDATE_LOCK_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Constructor and Description |
---|
Service() |
Modifier and Type | Method and Description |
---|---|
void |
attach(Context context,
ActivityThread thread,
String className,
IBinder token,
Application application,
Object activityManager) |
protected void |
dump(FileDescriptor fd,
PrintWriter writer,
String[] args)
Print the Service's state into the given stream.
|
Application |
getApplication()
Return the application that owns this service.
|
abstract IBinder |
onBind(Intent intent)
Return the communication channel to the service.
|
void |
onConfigurationChanged(Configuration newConfig)
Called by the system when the device configuration changes while your
component is running.
|
void |
onCreate()
Called by the system when the service is first created.
|
void |
onDestroy()
Called by the system to notify a Service that it is no longer used and is being removed.
|
void |
onLowMemory()
This is called when the overall system is running low on memory, and
would like actively running process to try to tighten their belt.
|
void |
onRebind(Intent intent)
Called when new clients have connected to the service, after it had
previously been notified that all had disconnected in its
onUnbind(android.content.Intent) . |
void |
onStart(Intent intent,
int startId)
Deprecated.
Implement
onStartCommand(Intent, int, int) instead. |
int |
onStartCommand(Intent intent,
int flags,
int startId)
Called by the system every time a client explicitly starts the service by calling
Context.startService(android.content.Intent) , providing the arguments it supplied and a
unique integer token representing the start request. |
void |
onTaskRemoved(Intent rootIntent)
This is called if the service is currently running and the user has
removed a task that comes from the service's application.
|
void |
onTrimMemory(int level)
Called when the operating system has determined that it is a good
time for a process to trim unneeded memory from its process.
|
boolean |
onUnbind(Intent intent)
Called when all clients have disconnected from a particular interface
published by the service.
|
void |
setForeground(boolean isForeground)
Deprecated.
This is a now a no-op, use
startForeground(int, Notification) instead. This method
has been turned into a no-op rather than simply being deprecated
because analysis of numerous poorly behaving devices has shown that
increasingly often the trouble is being caused in part by applications
that are abusing it. Thus, given a choice between introducing
problems in existing applications using this API (by allowing them to
be killed when they would like to avoid it), vs allowing the performance
of the entire system to be decreased, this method was deemed less
important. |
void |
startForeground(int id,
Notification notification)
Make this service run in the foreground, supplying the ongoing
notification to be shown to the user while in this state.
|
void |
stopForeground(boolean removeNotification)
Remove this service from foreground state, allowing it to be killed if
more memory is needed.
|
void |
stopSelf()
Stop the service, if it was previously started.
|
void |
stopSelf(int startId)
Old version of
stopSelfResult(int) that doesn't return a result. |
boolean |
stopSelfResult(int startId)
Stop the service if the most recent time it was started was
startId.
|
attachBaseContext, bindService, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createDisplayContext, createPackageContext, createPackageContextAsUser, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getCompatibilityInfo, getContentResolver, getDatabasePath, getDir, getExternalCacheDir, getExternalFilesDir, getFilesDir, getFileStreamPath, getMainLooper, getObbDir, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSharedPrefsFile, getSystemService, getTheme, getThemeResId, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiverAsUser, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivitiesAsUser, startActivity, startActivity, startActivityAsUser, startActivityAsUser, startInstrumentation, startIntentSender, startIntentSender, startService, startServiceAsUser, stopService, stopServiceAsUser, unbindService, unregisterReceiver
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
public static final int START_CONTINUATION_MASK
onStartCommand(android.content.Intent, int, int)
describing how to continue
the service if it is killed. May be START_STICKY
,
START_NOT_STICKY
, START_REDELIVER_INTENT
,
or START_STICKY_COMPATIBILITY
.public static final int START_STICKY_COMPATIBILITY
onStartCommand(android.content.Intent, int, int)
: compatibility
version of START_STICKY
that does not guarantee that
onStartCommand(android.content.Intent, int, int)
will be called again after being killed.public static final int START_STICKY
onStartCommand(android.content.Intent, int, int)
: if this service's
process is killed while it is started (after returning from
onStartCommand(android.content.Intent, int, int)
), then leave it in the started state but
don't retain this delivered intent. Later the system will try to
re-create the service. Because it is in the started state, it will
guarantee to call onStartCommand(android.content.Intent, int, int)
after creating the new
service instance; if there are not any pending start commands to be
delivered to the service, it will be called with a null intent
object, so you must take care to check for this.
This mode makes sense for things that will be explicitly started and stopped to run for arbitrary periods of time, such as a service performing background music playback.
public static final int START_NOT_STICKY
onStartCommand(android.content.Intent, int, int)
: if this service's
process is killed while it is started (after returning from
onStartCommand(android.content.Intent, int, int)
), and there are no new start intents to
deliver to it, then take the service out of the started state and
don't recreate until a future explicit call to
Context.startService(Intent)
. The
service will not receive a onStartCommand(Intent, int, int)
call with a null Intent because it will not be re-started if there
are no pending Intents to deliver.
This mode makes sense for things that want to do some work as a
result of being started, but can be stopped when under memory pressure
and will explicit start themselves again later to do more work. An
example of such a service would be one that polls for data from
a server: it could schedule an alarm to poll every N minutes by having
the alarm start its service. When its onStartCommand(android.content.Intent, int, int)
is
called from the alarm, it schedules a new alarm for N minutes later,
and spawns a thread to do its networking. If its process is killed
while doing that check, the service will not be restarted until the
alarm goes off.
public static final int START_REDELIVER_INTENT
onStartCommand(android.content.Intent, int, int)
: if this service's
process is killed while it is started (after returning from
onStartCommand(android.content.Intent, int, int)
), then it will be scheduled for a restart
and the last delivered Intent re-delivered to it again via
onStartCommand(android.content.Intent, int, int)
. This Intent will remain scheduled for
redelivery until the service calls stopSelf(int)
with the
start ID provided to onStartCommand(android.content.Intent, int, int)
. The
service will not receive a onStartCommand(Intent, int, int)
call with a null Intent because it will will only be re-started if
it is not finished processing all Intents sent to it (and any such
pending events will be delivered at the point of restart).public static final int START_TASK_REMOVED_COMPLETE
onTaskRemoved(Intent)
.public static final int START_FLAG_REDELIVERY
onStartCommand(android.content.Intent, int, int)
if the Intent is a
re-delivery of a previously delivered intent, because the service
had previously returned START_REDELIVER_INTENT
but had been
killed before calling stopSelf(int)
for that Intent.public static final int START_FLAG_RETRY
onStartCommand(android.content.Intent, int, int)
if the Intent is a
a retry because the original attempt never got to or returned from
onStartCommand(Intent, int, int)
.public final Application getApplication()
public void onCreate()
@Deprecated public void onStart(Intent intent, int startId)
onStartCommand(Intent, int, int)
instead.public int onStartCommand(Intent intent, int flags, int startId)
Context.startService(android.content.Intent)
, providing the arguments it supplied and a
unique integer token representing the start request. Do not call this method directly.
For backwards compatibility, the default implementation calls
onStart(android.content.Intent, int)
and returns either START_STICKY
or START_STICKY_COMPATIBILITY
.
If you need your application to run on platform versions prior to API
level 5, you can use the following model to handle the older onStart(android.content.Intent, int)
callback in that case. The handleCommand
method is implemented by
you as appropriate:
Note that the system calls this on your
service's main thread. A service's main thread is the same
thread where UI operations take place for Activities running in the
same process. You should always avoid stalling the main
thread's event loop. When doing long-running operations,
network calls, or heavy disk I/O, you should kick off a new
thread, or use AsyncTask
.
intent
- The Intent supplied to Context.startService(android.content.Intent)
,
as given. This may be null if the service is being restarted after
its process has gone away, and it had previously returned anything
except START_STICKY_COMPATIBILITY
.flags
- Additional data about this start request. Currently either
0, START_FLAG_REDELIVERY
, or START_FLAG_RETRY
.startId
- A unique integer representing this specific request to
start. Use with stopSelfResult(int)
.START_CONTINUATION_MASK
bits.stopSelfResult(int)
public void onDestroy()
public void onConfigurationChanged(Configuration newConfig)
ComponentCallbacks
At the time that this function has been called, your Resources object will have been updated to return resource values matching the new configuration.
onConfigurationChanged
in interface ComponentCallbacks
newConfig
- The new device configuration.public void onLowMemory()
ComponentCallbacks
Applications that want to be nice can implement this method to release any caches or other unnecessary resources they may be holding on to. The system will perform a gc for you after returning from this method.
onLowMemory
in interface ComponentCallbacks
public void onTrimMemory(int level)
ComponentCallbacks2
To retrieve the processes current trim level at any point, you can
use ActivityManager.getMyMemoryState(RunningAppProcessInfo)
.
onTrimMemory
in interface ComponentCallbacks2
level
- The context of the trim, giving a hint of the amount of
trimming the application may like to perform. May be
ComponentCallbacks2.TRIM_MEMORY_COMPLETE
, ComponentCallbacks2.TRIM_MEMORY_MODERATE
,
ComponentCallbacks2.TRIM_MEMORY_BACKGROUND
, ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN
,
ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL
, ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW
,
or ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE
.public abstract IBinder onBind(Intent intent)
IBinder
is usually for a complex interface
that has been described using
aidl.
Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.
intent
- The Intent that was used to bind to this service,
as given to Context.bindService
. Note that any extras that were included with
the Intent at that point will not be seen here.public boolean onUnbind(Intent intent)
intent
- The Intent that was used to bind to this service,
as given to Context.bindService
. Note that any extras that were included with
the Intent at that point will not be seen here.onRebind(android.content.Intent)
method later called when new clients bind to it.public void onRebind(Intent intent)
onUnbind(android.content.Intent)
. This will only be called if the implementation
of onUnbind(android.content.Intent)
was overridden to return true.intent
- The Intent that was used to bind to this service,
as given to Context.bindService
. Note that any extras that were included with
the Intent at that point will not be seen here.public void onTaskRemoved(Intent rootIntent)
ServiceInfo.FLAG_STOP_WITH_TASK
then you will not receive this callback; instead, the service will simply
be stopped.rootIntent
- The original root Intent that was used to launch
the task that is being removed.public final void stopSelf()
Context.stopService(android.content.Intent)
for this particular service.stopSelfResult(int)
public final void stopSelf(int startId)
stopSelfResult(int)
that doesn't return a result.stopSelfResult(int)
public final boolean stopSelfResult(int startId)
Context.stopService(android.content.Intent)
for this particular service but allows you to
safely avoid stopping if there is a start request from a client that you
haven't yet seen in onStart(android.content.Intent, int)
.
Be careful about ordering of your calls to this function.. If you call this function with the most-recently received ID before you have called it for previously received IDs, the service will be immediately stopped anyway. If you may end up processing IDs out of order (such as by dispatching them on separate threads), then you are responsible for stopping them in the same order you received them.
startId
- The most recent start identifier received in onStart(android.content.Intent, int)
.stopSelf()
@Deprecated public final void setForeground(boolean isForeground)
startForeground(int, Notification)
instead. This method
has been turned into a no-op rather than simply being deprecated
because analysis of numerous poorly behaving devices has shown that
increasingly often the trouble is being caused in part by applications
that are abusing it. Thus, given a choice between introducing
problems in existing applications using this API (by allowing them to
be killed when they would like to avoid it), vs allowing the performance
of the entire system to be decreased, this method was deemed less
important.public final void startForeground(int id, Notification notification)
If you need your application to run on platform versions prior to API level 5, you can use the following model to call the the older setForeground() or this modern method as appropriate:
id
- The identifier for this notification as per
NotificationManager.notify(int, Notification)
.notification
- The Notification to be displayed.stopForeground(boolean)
public final void stopForeground(boolean removeNotification)
removeNotification
- If true, the notification previously provided
to startForeground(int, android.app.Notification)
will be removed. Otherwise it will remain
until a later call removes it (or the service is destroyed).startForeground(int, Notification)
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args)
IBinder.dump(java.io.FileDescriptor, java.lang.String[])
method
on the IBinder
interface registered with ServiceManager.fd
- The raw file descriptor that the dump is being sent to.writer
- The PrintWriter to which you should dump your state. This will be
closed for you after you return.args
- additional arguments to the dump request.public final void attach(Context context, ActivityThread thread, String className, IBinder token, Application application, Object activityManager)