The sendBroadcast() method allows to send Broadcast Intents. You cannot trigger system Broadcasts, the Android system will prevent this. But you can define intent-filters for your own actions and trigger them via the sendBroadcast() method.
localbroadcastmanager has been fully deprecated. There will be no further releases of this library. Developers should replace usages of LocalBroadcastManager with other implementations of the observable pattern. Depending on the use case, suitable options may be LiveData or reactive streams.
The Android system automatically sends broadcasts when various system events occur, such as when the system switches in and out of airplane mode. The system sends these broadcasts to all apps that are subscribed to receive the event.
"A Broadcast receiver is an Android component which allows you to register for system or application events." LocalBroadcastManager is a way to send or receive broadcasts within an application process. This mechanism has a lot of advantages.
LocalBroadcastManager is as its name says, an implementation of the broadcast methods that are only available to your app. This has some benefits, with the biggest being safety, one less hole to watch out for. In terms of implementation, there are a few things to keep in mind:
LocalBroadcastManager.getInstance([CONTEXT])
where [CONTEXT]
is a subclass of the Context class, such as Activity.So this class is not the same as Context, it is simply a very specific, app-only implementation of Context's receiver/broadcast methods. You should use it when there is absolutely no point for your listener to listen on global (system-wide) broadcasts and when your broadcast does not need to target anything outside your app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With