Android radio vs listeners

If you have a Service that often (every second or half a second) sends updates, are there any pros / cons to using Broadcasts vs registering Listeners (the interface you create) that are saved as a List in the service and sending updates this way?

I mean memory usage, battery consumption, etc. I know that it is a little open, but there is not much documentation there so that they can be equal, but if someone knows a specific answer or has some input, it would be appreciated.

+6
source share
3 answers

In my experience, if you send notifications often, select listeners. I implemented several BroadcastReceivers on the same issue, but some messages got lost. I think this is due to the fact that BroadcastReceivers do not put a queue on incoming intentions, but instead throw those who arrive, but still "do the work with the old." Of course, broadcasting intentions can be more relaxing, since you do not need to ... connect the service and every part of listening to your application, but in my case (a few messages per second), the listeners were the right choice.

+3
source

Do not think about it, it is really a small amount of energy and perfomanse. The main difference between broadcasts and listeners is the way your messages are sent. If he will broadcast your pluses, he will switch to another system, they will go directly to your class.

0
source

In any case, you need to create a BroadcastReciever to receive updates (so that it is still a listener). But in this case, os takes care to name them instead of direct listener calls from the service. Not sure about the value of the difference, but direct calls look faster and consume less memory / battery from this pov.

0
source

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


All Articles