0

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.

ar-g
  • 3,417
  • 2
  • 28
  • 39

1 Answers1

1

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.

Egor
  • 39,695
  • 10
  • 113
  • 130
  • Right! That mean if I don't want to keep this sticky event after next configChanges should I remove it? – ar-g Nov 24 '14 at 15:00
  • If you don't care about the event after configChanges - then you don't need to use sticky events in the first place. They add some overhead as they're caching events, so be sure to use this approach only if justified. – Egor Nov 24 '14 at 15:01