Skip to content

Most visited

Recently visited

navigation

ServiceCompat

public final class ServiceCompat
extends Object

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


Helper for accessing features in Service introduced after API level 9 in a backwards compatible fashion.

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

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

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

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

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.

See also:

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.