Skip to content

Most visited

Recently visited

navigation

LocalBroadcastManager

public final class LocalBroadcastManager
extends Object

java.lang.Object
   ↳ android.support.v4.content.LocalBroadcastManager


Helper to register for and send broadcasts of Intents to local objects within your process. This has a number of advantages over sending global broadcasts with sendBroadcast(Intent):

  • You know that the data you are broadcasting won't leave your app, so don't need to worry about leaking private data.
  • It is not possible for other applications to send these broadcasts to your app, so you don't need to worry about having security holes they can exploit.
  • It is more efficient than sending a global broadcast through the system.

Summary

Public methods

static LocalBroadcastManager getInstance(Context context)
void registerReceiver(BroadcastReceiver receiver, IntentFilter filter)

Register a receive for any local broadcasts that match the given IntentFilter.

boolean sendBroadcast(Intent intent)

Broadcast the given intent to all interested BroadcastReceivers.

void sendBroadcastSync(Intent intent)

Like sendBroadcast(Intent), but if there are any receivers for the Intent this function will block and immediately dispatch them before returning.

void unregisterReceiver(BroadcastReceiver receiver)

Unregister a previously registered BroadcastReceiver.

Inherited methods

From class java.lang.Object

Public methods

getInstance

added in version 22.0.0
LocalBroadcastManager getInstance (Context context)

Parameters
context Context

Returns
LocalBroadcastManager

registerReceiver

added in version 22.0.0
void registerReceiver (BroadcastReceiver receiver, 
                IntentFilter filter)

Register a receive for any local broadcasts that match the given IntentFilter.

Parameters
receiver BroadcastReceiver: The BroadcastReceiver to handle the broadcast.

filter IntentFilter: Selects the Intent broadcasts to be received.

See also:

sendBroadcast

added in version 22.0.0
boolean sendBroadcast (Intent intent)

Broadcast the given intent to all interested BroadcastReceivers. This call is asynchronous; it returns immediately, and you will continue executing while the receivers are run.

Parameters
intent Intent: The Intent to broadcast; all receivers matching this Intent will receive the broadcast.

Returns
boolean Returns true if the intent has been scheduled for delivery to one or more broadcast receivers. (Note tha delivery may not ultimately take place if one of those receivers is unregistered before it is dispatched.)

See also:

sendBroadcastSync

added in version 22.0.0
void sendBroadcastSync (Intent intent)

Like sendBroadcast(Intent), but if there are any receivers for the Intent this function will block and immediately dispatch them before returning.

Parameters
intent Intent

unregisterReceiver

added in version 22.0.0
void unregisterReceiver (BroadcastReceiver receiver)

Unregister a previously registered BroadcastReceiver. All filters that have been registered for this BroadcastReceiver will be removed.

Parameters
receiver BroadcastReceiver: The BroadcastReceiver to unregister.

See also:

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

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

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.

Take a one-minute survey?
Help us improve Android tools and documentation.