priority 數值越大優先順序又高
// MainActivity @Subscribe(priority = 2) public void onMessageEvent(MessageEvent event) { Toast.makeText(this, event.message, Toast.LENGTH_SHORT).show(); } // SecondActivity @Subscribe(priority = 1) public void onMessageSecondEvent(MessageEvent event) { Toast.makeText(this, event.message, Toast.LENGTH_SHORT).show(); }
時間攔截,MainActivity 收到信息後調用 EventBus.getDefault().cancelEventDelivery(event); 之後所有訂閲將收不到信息。
// MainActivity @Subscribe(priority = 2) public void onMessageEvent(MessageEvent event) { Toast.makeText(this, event.message, Toast.LENGTH_SHORT).show(); EventBus.getDefault().cancelEventDelivery(event); } // SecondActivity @Subscribe(priority = 1) public void onMessageSecondEvent(MessageEvent event) { Toast.makeText(this, event.message, Toast.LENGTH_SHORT).show(); }