Package 

Class LocalBroadcastManager


  • 
    public class LocalBroadcastManager
    
                        

    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 sendBroadcast:

    • 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.
    • Method Summary

      Modifier and Type Method Description
      void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) Register a receive for any local broadcasts that match the given IntentFilter.
      void unregisterReceiver(BroadcastReceiver receiver) Unregister a previously registered BroadcastReceiver.
      boolean sendBroadcast(Intent intent) Broadcast the given intent to all interested BroadcastReceivers.
      void sendBroadcastSync(Intent intent) Like sendBroadcast, but if there are any receivers forthe Intent this function will block and immediately dispatch them beforereturning.
      • Methods inherited from class java.lang.Object

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

      • LocalBroadcastManager

        LocalBroadcastManager(Context context)
    • Method Detail

      • registerReceiver

         void registerReceiver(BroadcastReceiver receiver, 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.
      • unregisterReceiver

         void unregisterReceiver(BroadcastReceiver receiver)

        Unregister a previously registered BroadcastReceiver. Allfilters that have been registered for this BroadcastReceiver will beremoved.

        Parameters:
        receiver - The BroadcastReceiver to unregister.
      • sendBroadcast

         boolean sendBroadcast(Intent intent)

        Broadcast the given intent to all interested BroadcastReceivers. Thiscall is asynchronous; it returns immediately, and you will continueexecuting while the receivers are run.

        Parameters:
        intent - The Intent to broadcast; all receivers matching thisIntent will receive the broadcast.
      • sendBroadcastSync

         void sendBroadcastSync(Intent intent)

        Like sendBroadcast, but if there are any receivers forthe Intent this function will block and immediately dispatch them beforereturning.