Android.Content.Context.BindService Method
Connect to an application service, creating it if needed.

Syntax

[Android.Runtime.Register("bindService", "(Landroid/content/Intent;Landroid/content/ServiceConnection;I)Z", "GetBindService_Landroid_content_Intent_Landroid_content_ServiceConnection_IHandler")]
public abstract bool BindService (Intent service, IServiceConnection conn, [Android.Runtime.GeneratedEnum] Bind flags)

See Also

Context.UnbindService(IServiceConnection)
Context.StartService(Intent)

Parameters

service
Identifies the service to connect to. The Intent may specify either an explicit component name, or a logical description (action, category, etc) to match an Android.Content.IntentFilter published by a service.
conn
Receives information as the service is started and stopped. This must be a valid ServiceConnection object; it must not be null.
flags
Operation options for the binding. May be 0, Context.BIND_AUTO_CREATE, Context.BIND_DEBUG_UNBIND, Context.BIND_NOT_FOREGROUND, Context.BIND_ABOVE_CLIENT, Context.BIND_ALLOW_OOM_MANAGEMENT, or Context.BIND_WAIVE_PRIORITY.

Returns

Documentation for this section has not yet been entered.

Exceptions

TypeReason
Java.Lang.SecurityException 

Remarks

Connect to an application service, creating it if needed. This defines a dependency between your application and the service. The given conn will receive the service object when it is created and be told if it dies and restarts. The service will be considered required by the system only for as long as the calling context exists. For example, if this Context is an Activity that is stopped, the service will not be required to continue running until the Activity is resumed.

This function will throw Java.Lang.SecurityException if you do not have permission to bind to the given service.

Note: this method can not be called from a Android.Content.BroadcastReceiver component. A pattern you can use to communicate from a BroadcastReceiver to a Service is to call Context.StartService(Intent) with the arguments containing the command to be sent, with the service calling its Android.App.Service.StopSelf(int) method when done executing that command. See the API demo App/Service/Service Start Arguments Controller for an illustration of this. It is okay, however, to use this method from a BroadcastReceiver that has been registered with Context.RegisterReceiver(BroadcastReceiver, Android.Content.IntentFilter), since the lifetime of this BroadcastReceiver is tied to another object (the one that registered it).

[Android Documentation]

Requirements

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