The @Subscribe method is called multiple times for the same event

In my code, I listen to events using @Subscribe anotation:

 @Subscribe public void orderUpdate(OrderUpdateEvent event) 

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

This is how I send this event:

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

What could be the reason for this? Am I missing something?

+6
source share
1 answer

What could be the reason for this?

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

+4
source

Source: https://habr.com/ru/post/981189/


All Articles