6

In my code I'm listening for events using @Subscribe anotation:

@Subscribe
public void orderUpdate(OrderUpdateEvent event)

My problem is that this method is called multiple times (1-3 depends from run to run) for the same event object.

This is how I send this event:

busProvider.getEventBus().postOnMain(new OrderUpdateEvent();

What could be the cause of that? Do I'm missing something?

skywalker
  • 318
  • 4
  • 10

1 Answers1

6

What could be the cause of that?

One possibility is that you have three instances of this class still registered on the event bus. Make sure that you unregister() when the object should no longer receive messages.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    I have similar question: For example I received event in `@Subscribe` method, than I closed `Fragment` and unregistered Bus in method `onPause`. After that I opened `Fragment` again, registered Bus in method `onResume` and received the same event that I already handled before. I don't want to receive same Event every time I back to the `Fragment`. Any ideas how to avoid this? – Volodymyr Mar 27 '15 at 08:09
  • @vovaxo: I do not know how that would happen with Otto. – CommonsWare Mar 27 '15 at 10:03
  • @vovaxo are you sure this is the same Event object? – skywalker Mar 27 '15 at 11:56
  • @skywalker I'm sure. Maybe I have a bit different situation. I am sending event from `Service` – Volodymyr Mar 27 '15 at 12:29