lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

belongs to Maven artifact androidx.core:core:1.0.0-alpha3

ServiceCompat

public final class ServiceCompat
extends Object

java.lang.Object
   ↳ androidx.core.app.ServiceCompat


Helper for accessing features in Service.

Summary

Constants

int START_STICKY

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

Constants

START_STICKY

public static final int START_STICKY

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

public static final 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. 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.

Constant Value: 2 (0x00000002)

STOP_FOREGROUND_REMOVE

public static final int STOP_FOREGROUND_REMOVE

Flag for 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.

Constant Value: 1 (0x00000001)

Public methods

stopForeground

public static 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.