Class LocalBroadcastManager


  • public class LocalBroadcastManager
    extends java.lang.Object
    Helper to register for and send broadcasts of Intents to local objects within your process. This is has a number of advantages over sending global broadcasts with Context.sendBroadcast(android.content.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.
    • Constructor Summary

      Constructors 
      Constructor Description
      LocalBroadcastManager​(android.content.Context context)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void registerReceiver​(android.content.BroadcastReceiver receiver, android.content.IntentFilter filter)
      Register a receive for any local broadcasts that match the given IntentFilter.
      boolean sendBroadcast​(android.content.Intent intent)
      Broadcast the given intent to all interested BroadcastReceivers.
      void sendBroadcastSync​(android.content.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​(android.content.BroadcastReceiver receiver)
      Unregister a previously registered BroadcastReceiver.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LocalBroadcastManager

        public LocalBroadcastManager​(android.content.Context context)
    • Method Detail

      • registerReceiver

        public void registerReceiver​(android.content.BroadcastReceiver receiver,
                                     android.content.IntentFilter filter)
        Register a receive for any local broadcasts that match the given IntentFilter.
        Parameters:
        receiver - The BroadcastReceiver to handle the broadcast.
        filter - Selects the Intent broadcasts to be received.
        See Also:
        unregisterReceiver(android.content.BroadcastReceiver)
      • sendBroadcast

        public boolean sendBroadcast​(android.content.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 - The Intent to broadcast; all receivers matching this Intent will receive the broadcast.
        See Also:
        registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter)
      • sendBroadcastSync

        public void sendBroadcastSync​(android.content.Intent intent)
        Like sendBroadcast(Intent), but if there are any receivers for the Intent this function will block and immediately dispatch them before returning.