Will EventBus.post() deliver event if configChanges occur or if activity in background?

234 views Asked by At

I read documentation here but there is no clear explanation will event trigger if configChanges occur in activity or if activity in background with EventBus.getDefault().post() . Now I'm using EventBus like this:

EventBus.getDefault.postSticky(new SomeEvent());

public void onEventMainThread(SomeEvent someEvent){
        EventBus.getDefault().removeStickyEvent(someEvent);

}

I would like to avoid this boilerplate code.

1

There are 1 answers

2
Egor On BEST ANSWER

The Activity will obviously not receive any events between unregister() in onDestroy() and register() in onCreate() - remember that by default the Activity will be fully recreated when configuration changes. However, if you registerSticky() then you'll have access to the latest published event, even if it arrived at the moment of Activity recreation.