Events being received multiple times - Greenrobot eventbus

Russ Wheeler picture Russ Wheeler · Jan 24, 2015 · Viewed 8.2k times · Source

I am using Greenrobot's EventBus in my app, and it works fine.

However, if I press the back button to close the app, then restart the app instantly I seem to receive the event twice. If I then do so again, I will receive it three times and so on.

I am checking with logs and debugging to see if I have multiple instances of any classes, or if I am registering multiple times, but I can't see any extra classes and using isRegistered returns false.

Any ideas?

Thanks

Answer

Maik picture Maik · Jan 24, 2015

Are your register/unregister calls paired correctly? E.g. if you register() in Activity.onResume(), are you calling unregister() in Activity.onPause().

Closing all activities does not kill your process. I.e. all registered classes are still there, you have to explicitly clean up and unregister from the event bus, or reuse them when the Activity comes back.