Android Guides | Samples

Android.Content.Context.RegisterReceiver Method

Register a BroadcastReceiver to be run in the main activity thread.


[Android.Runtime.Register("registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;", "GetRegisterReceiver_Landroid_content_BroadcastReceiver_Landroid_content_IntentFilter_Handler")]
public abstract Intent RegisterReceiver (BroadcastReceiver receiver, IntentFilter filter)

See Also


The BroadcastReceiver to handle the broadcast.
Selects the Intent broadcasts to be received.


Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.

The system may broadcast Intents that are "sticky" -- these stay around after the broadcast as finished, to be sent to any later registrations. If your IntentFilter matches one of these sticky Intents, that Intent will be returned by this function and sent to your receiver as if it had just been broadcast.

There may be multiple sticky Intents that match filter, in which case each of these will be sent to receiver. In this case, only one of these can be returned directly by the function; which of these that is returned is arbitrarily decided by the system.

If you know the Intent your are registering for is sticky, you can supply null for your receiver. In this case, no receiver is registered -- the function simply returns the sticky Intent that matches filter. In the case of multiple matches, the same rules as described above apply.

See BroadcastReceiver for more information on Intent broadcasts.

As of NoType:android/os/Build$VERSION_CODES;Href=../../../reference/android/os/Build.VERSION_CODES.html#ICE_CREAM_SANDWICH, receivers registered with this method will correctly respect the Intent.SetPackage(String) specified for an Intent being broadcast. Prior to that, it would be ignored and delivered to all matching registered receivers. Be careful if using this for security.

Note: this method cannot be called from a BroadcastReceiver component; that is, from a BroadcastReceiver that is declared in an application's manifest. It is okay, however, to call this method from another BroadcastReceiver that has itself been registered at run time with Context.RegisterReceiver(BroadcastReceiver,IntentFilter), since the lifetime of such a registered BroadcastReceiver is tied to the object that registered it.

[Android Documentation]


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