EventBus icon indicating copy to clipboard operation
EventBus copied to clipboard

Ability to be notified when subscribers are added/removed

Open palto-blubek opened this issue 8 years ago • 2 comments

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.

palto-blubek avatar Mar 17 '17 19:03 palto-blubek

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

greenrobot-team avatar Mar 20 '17 06:03 greenrobot-team

It would be great if there was a listener API for this :)

BoD avatar Mar 20 '17 06:03 BoD