Is there any way to find out if LocalBroadcastManager broadcasts were received?

Is there any way to find out if LocalBroadcastManager broadcasts were received? Or are they obeying?

Basically, I have an IntentService while listening to Google Virtual Messages. When he receives one, I need to either show a notification or warn my main service that a new message has appeared - in principle, I do not want both of them! So I need to know if the message was processed by my main service ...

Clearly this can be done with sendOrderedBroadcast and BroadcastReceiver, but this seems redundant for my simple private in-process needs.

+6
source share
1 answer

Is there any way to find out if LocalBroadcastManager broadcasts were received? Or are they obeying?

sendBroadcast() returns true if there are 1+ receivers, false otherwise. This is not documented, but it is based on the current implementation. I registered a problem for documentation .

Therefore, your IntentService can use sendBroadcast() to try and send a message to your Service start, if one exists. If so, sendBroadcast() should return true , and the IntentService knows that the message should be processed there. If sendBroadcast() returns false , you can raise Notification .

+25
source

Source: https://habr.com/ru/post/952922/


All Articles