What is a LocalBroadcastManager?

Technology CommunityCategory: AndroidWhat is a LocalBroadcastManager?
VietMX Staff asked 3 years ago

It is good practice to use broadcast receivers when you want to send or receive data between different applications. But if the communication is limited to your application then it is not good to use the global broadcast.

In this case Android provides local broadcasts with the LocalBroadcastManager class. Using global broadcast, any other application can also send and receives broadcast messages to and from our application. This can be a serious security thread for our application. Also global broadcast is sent system-wide, so it is not performance efficient.

The LocalBroadcastManager is much more efficient as it doesn’t need inter-process communication. Below are some of its benefits:

  • Broadcast data 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.
  • No overhead of system-wide broadcast.