EventBus
EventBus copied to clipboard
Ability to be notified when subscribers are added/removed
Hi! I was working on a "location manager" that handles starting a Google Play Services client, then starts to listen to location changes, and sends them using EventBus. Then I realized that, for battery saving reasons, the listening to locations changes should be only started if there is at least one interested party (a component that subscribed to my event). And it should stop when there are no more subscribers.
I didn't find a way to be notified when subscribers of a particular event are added/removed - did I miss an API or is this something that was considered? Or maybe there is another way to do this?
Thanks a lot.
You should be able to check .hasSubscriberForEvent(Class<?> eventClass) on your EventBus instance.
Edit: sorry, meaning there are no notifications if somebody registers or unregisters. You have to track this yourself or use another mechanism (like using a service that you bind to). -ut
It would be great if there was a listener API for this :)