1

I recently changed my app to be less dependent on other parts of the application by switching to eventbus. Now I am seeing a strange issue, I don't know if its a bug or intended feature of green robot's eventbus.

Say I have an Event A and Event B, Well event B extends A since A is a generic event of type A. My helper classes have a subscribe to both Events A and B, what I am seeing is it fires B, then A. Is there a way to prevent this from occurring while keeping my polymorphism other than checking if its an instanceof in the generic subscribe listener? I use the A event as a broadcast of types should it need to be handled in more than one class.

Thanks

bhawkins
  • 326
  • 2
  • 11

1 Answers1

0

I know this is an old post, but you can do this by setting up your event bus like this:

 EventBus EVENT_BUS = new EventBus().builder().eventInheritance(false).installDefaultEventBus();

The key here is the eventInheritance(Boolean) method. I had this same issue happen to me, and when I built the bus instance this way, only the event that you are subscribed to will fire. So if you fire the the Event B, only the Event B subscriber will fire, not the Event A.

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156