Reputation: 3450
I'm trying to pass an event with Otto Event Bus from the SplashActivity to LoginActivity which is 2 o 3 activities later with:
SplashActivity
@Override
public void onStart() {
super.onStart();
BusProvider.getInstance().register(this);
if(UtilityManager.isAppOpenedFromNotificationTap(this)){
BusProvider.getInstance().post(new AppOpenedFromNotificationClickEvent());
}
}
@Override
public void onStop() {
super.onStop();
BusProvider.getInstance().unregister(this);
}
And I am getting value with:
LoginActivity
@Override
public void onStart() {
super.onStart();
BusProvider.getInstance().register(this);
}
@Override
public void onStop() {
super.onStop();
BusProvider.getInstance().unregister(this);
}
@Subscribe
public void onAppOpenedFromNotificationEvent(AppOpenedFromNotificationClickEvent event) {
Log.e("LOGIN", "ARRIVED" );
appOpenedFromNotification = true;
}
These Log that I put inside subscribe is never showed. What the problem?
Upvotes: 0
Views: 494
Reputation: 980
Use a sticky event
for sending
EventBus.getDefault().postSticky(new MessageEvent("Hello everyone!"));
for receiving
// UI updates must run on MainThread
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(MessageEvent event) {
textField.setText(event.message);
}
Upvotes: 1