Join us on the livestream at Android Dev Summit on 7-8 November 2018, starting at 10AM PDT!
added in version 22.1.0
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1

ServiceCompat

public final class ServiceCompat
extends Object

java.lang.Object
   ↳ android.support.v4.app.ServiceCompat


Helper for accessing features in Service.

Summary

Constants

int START_STICKY

Constant to return from onStartCommand(Intent, int, int): if this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int)), then leave it in the started state but don't retain this delivered intent.

int STOP_FOREGROUND_DETACH

Flag for stopForeground(Service, int): if set, the notification previously provided to startForeground(int, Notification) will be detached from the service.

int STOP_FOREGROUND_REMOVE

Flag for stopForeground(Service, int): if set, the notification previously provided to startForeground(int, Notification) will be removed.

Public methods

static void stopForeground(Service service, int flags)

Remove the passed service from foreground state, allowing it to be killed if more memory is needed.

Inherited methods

From class java.lang.Object

Constants

START_STICKY

added in version 22.1.0
int START_STICKY

Constant to return from onStartCommand(Intent, int, int): if this service's process is killed while it is started (after returning from onStartCommand(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(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.

Constant Value: 1 (0x00000001)

STOP_FOREGROUND_DETACH

added in version 25.1.0
int STOP_FOREGROUND_DETACH

Flag for stopForeground(Service, int): if set, the notification previously provided to 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 N and later. It doesn't have any effect on earlier platform versions.

Constant Value: 2 (0x00000002)

STOP_FOREGROUND_REMOVE

added in version 25.1.0
int STOP_FOREGROUND_REMOVE

Flag for stopForeground(Service, int): if set, the notification previously provided to startForeground(int, Notification) will be removed. Otherwise it will remain until a later call (to startForeground(int, Notification) or stopForeground(Service, int) removes it, or the service is destroyed.

Constant Value: 1 (0x00000001)

Public methods

stopForeground

added in version 25.1.0
void stopForeground (Service service, 
                int flags)

Remove the passed service from foreground state, allowing it to be killed if more memory is needed.

Parameters
service Service

flags int: Additional behavior options: STOP_FOREGROUND_REMOVE, STOP_FOREGROUND_DETACH.