Reputation: 5975
If you have a Service that frequently (every second or half a second) sends updates, are there pros/cons to using Broadcasts vs registering Listeners (an Interface you create) that get stored in some sort of List in the Service and sending out updates that way?
I'm thinking in terms of memory usage, battery consumption, etc. I know it's a little bit open ended, however, there's not much in terms of documentation so they can be equal, but if someone knows a definite answer or has some input, it would be appreciated.
Upvotes: 6
Views: 4061
Reputation: 2011
In my experience, if you will send out notifications frequently, choose listeners. I've implemented some BroadcastReceivers for the same matter, but some messages got lost. I think this is because the BroadcastReceivers do not queue incoming intents but instead drop those arriving whilst still "doing work with the old one". Of course broadcasting intents can be more relaxing, as you don't have to.. connect the service and every listening part of your application, but in my case (multiple messages per second) listeners were the right choice.
Upvotes: 4
Reputation: 51
Anyway you should create a BroadcastReciever to get updates (so it's still a listener). But in this case os cares to call them instead of direct listener calls from service. Not sure about value of differance, but direct calls looks faster, and less memory/battery consumpting from this pov.
Upvotes: 0
Reputation: 950
Do not think about this things, it is really small amount of energy and perfomanse. Main difference between Broadcasts and Listeners is a way there your messages will go. If it's Broadcasts your ivents will go throgh system othervise they will go directly to your class.
Upvotes: 0