Android.App.Service.OnStartCommand Method
Called by the system every time a client explicitly starts the service by calling Android.Content.Context.StartService(Android.Content.Intent), providing the arguments it supplied and a unique integer token representing the start request.

Syntax

[Android.Runtime.Register("onStartCommand", "(Landroid/content/Intent;II)I", "GetOnStartCommand_Landroid_content_Intent_IIHandler")]
[System.Obsolete("deprecated")]
[return:Android.Runtime.GeneratedEnum]
public virtual StartCommandResult OnStartCommand (Android.Content.Intent intent, [Android.Runtime.GeneratedEnum] StartCommandFlags flags, int startId)

See Also

Service.StopSelfResult(int)

Parameters

intent
The Intent supplied to Android.Content.Context.StartService(Android.Content.Intent), as given. This may be null if the service is being restarted after its process has gone away, and it had previously returned anything except Service.START_STICKY_COMPATIBILITY.
flags
Additional data about this start request. Currently either 0, Service.START_FLAG_REDELIVERY, or Service.START_FLAG_RETRY.
startId
A unique integer representing this specific request to start. Use with Service.StopSelfResult(int).

Returns

Documentation for this section has not yet been entered.

Remarks

Called by the system every time a client explicitly starts the service by calling Android.Content.Context.StartService(Android.Content.Intent), providing the arguments it supplied and a unique integer token representing the start request. Do not call this method directly.

For backwards compatibility, the default implementation calls Service.OnStart(Android.Content.Intent, System.Int32) and returns either Service.START_STICKY or Service.START_STICKY_COMPATIBILITY.

If you need your application to run on platform versions prior to API level 5, you can use the following model to handle the older Service.OnStart(Android.Content.Intent, System.Int32) callback in that case. The handleCommand method is implemented by you as appropriate:

java Example

// This is the old onStart method that will be called on the pre-2.0
// platform.  On 2.0 or later we override onStartCommand() so this
// method will not be called.
@Override
public void onStart(Intent intent, int startId) {
    handleCommand(intent);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    handleCommand(intent);
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

Note that the system calls this on your service's main thread. A service's main thread is the same thread where UI operations take place for Activities running in the same process. You should always avoid stalling the main thread's event loop. When doing long-running operations, network calls, or heavy disk I/O, you should kick off a new thread, or use Android.OS.AsyncTask`3.

[Android Documentation]

Requirements

Namespace: Android.App
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 5