@Subscribe method called multiple time for the same event
Asked Answered
S

1

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?

Shultz answered 18/1, 2015 at 22:31 Comment(2)
have you already found solution for you problem?Insurmountable
yes, as @CommonsWare suggested unregister() was not called.Shultz
K
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.

Kristopherkristos answered 18/1, 2015 at 22:49 Comment(4)
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?Insurmountable
@vovaxo: I do not know how that would happen with Otto.Kristopherkristos
@vovaxo are you sure this is the same Event object?Shultz
@Shultz I'm sure. Maybe I have a bit different situation. I am sending event from ServiceInsurmountable

© 2022 - 2024 — McMap. All rights reserved.