Android Guides | Samples

Android.App.StartCommandResult Enumeration

Enumerates values returned by several types.

Syntax

[System.Flags]
public enum StartCommandResult

Remarks

Members

Member NameDescription
ContinuationMaskBits returned by Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags) describing how to continue the service if it is killed. May be StartCommandResult.Sticky, StartCommandResult.NotSticky, StartCommandResult.RedeliverIntent, or StartCommandResult.StickyCompatibility.
NotSticky

Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)Context.StartService(Intent)Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)

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 Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags) 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.

RedeliverIntentConstant to return from Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags): if this service's process is killed while it is started (after returning from Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)), then it will be scheduled for a restart and the last delivered Intent re-delivered to it again via Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags). This Intent will remain scheduled for redelivery until the service calls Service.StopSelf(Int32) with the start ID provided to Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags). The service will not receive a Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags) 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).
Sticky

Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)

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.

StickyCompatibilityConstant to return from Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags): compatibility version of StartCommandResult.Sticky that does not guarantee that Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags) will be called again after being killed.

Requirements

Namespace: Android.App
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0

The members of Android.App.StartCommandResult are listed below.

See Also: Enum

Public Fields

ContinuationMaskStartCommandResult. Bits returned by Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags) describing how to continue the service if it is killed. May be StartCommandResult.Sticky, StartCommandResult.NotSticky, StartCommandResult.RedeliverIntent, or StartCommandResult.StickyCompatibility.
NotStickyStartCommandResult.

Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)Context.StartService(Intent)Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)

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 Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags) 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.

RedeliverIntentStartCommandResult. Constant to return from Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags): if this service's process is killed while it is started (after returning from Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)), then it will be scheduled for a restart and the last delivered Intent re-delivered to it again via Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags). This Intent will remain scheduled for redelivery until the service calls Service.StopSelf(Int32) with the start ID provided to Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags). The service will not receive a Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags) 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).
StickyStartCommandResult.

Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags)

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.

StickyCompatibilityStartCommandResult. Constant to return from Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags): compatibility version of StartCommandResult.Sticky that does not guarantee that Service.OnStartCommand(Intent,StartCommandFlags,StartCommandFlags) will be called again after being killed.