Modifier and Type | Class and Description |
---|---|
static interface |
ServiceCompat.StopForegroundFlags |
Modifier and Type | Field and Description |
---|---|
static int |
START_STICKY
Constant to return from
Service.onStartCommand(android.content.Intent, int, int) : if this
service's process is killed while it is started (after returning from
Service.onStartCommand(android.content.Intent, int, int) ), then leave it in the started
state but don't retain this delivered intent. |
static int |
STOP_FOREGROUND_DETACH
Flag for
stopForeground(Service, int) : if set, the notification previously provided
to Service.startForeground(int, Notification) will be detached from the service. |
static int |
STOP_FOREGROUND_REMOVE
Flag for
stopForeground(Service, int) : if set, the notification previously provided
to Service.startForeground(int, Notification) will be removed. |
Modifier and Type | Method and Description |
---|---|
static void |
stopForeground(Service service,
int flags)
Remove the passed service from foreground state, allowing it to be killed if
more memory is needed.
|
public static final int START_STICKY
Service.onStartCommand(android.content.Intent, int, int)
: if this
service's process is killed while it is started (after returning from
Service.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 Service.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 STOP_FOREGROUND_REMOVE
stopForeground(Service, int)
: if set, the notification previously provided
to Service.startForeground(int, Notification)
will be removed. Otherwise it
will remain until a later call (to Service.startForeground(int, Notification)
or
stopForeground(Service, int)
removes it, or the service is destroyed.public static final int STOP_FOREGROUND_DETACH
stopForeground(Service, int)
: if set, the notification previously provided
to Service.startForeground(int, Notification)
will be detached from the service.
Only makes sense when STOP_FOREGROUND_REMOVE
is not set -- in this case, the
notification will remain shown, but be completely detached from the service and so no longer
changed except through direct calls to the
notification manager.
This flag will only work on
Build.VERSION_CODES.N
and later. It doesn't have any effect on earlier
platform versions.
public static void stopForeground(Service service, int flags)
flags
- Additional behavior options: STOP_FOREGROUND_REMOVE
,
STOP_FOREGROUND_DETACH
.Service.startForeground(int, Notification)