我正在使用事件总线将数据从通知服务传递到活动。但没有得到任何主要活动的消息。我的代码是。
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
EventBus.getDefault().postSticky(new String("Send data"));
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(String event) {
// your implementation
Toast.makeText(this, event, Toast.LENGTH_SHORT).show();
}
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onMessageEvent(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
public void onEventMainThread(MessageEvent event) {
Toast.makeText(this, event + "", Toast.LENGTH_SHORT).show();
}
@Override
protected void onResume() {
super.onResume();
InstaOrderApp.getInstance(this).setCurrentactvity(this);
EventBus.getDefault().register(this);
updateTableQty();
}
任何人请帮帮我问题在哪里? 感谢
答案 0 :(得分:1)
您是否在onStart方法上注册了活动总线?
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}