eventbus指定接收者

http://greenrobot.org/eventbus/documentation/priorities-and-event-cancellation/

思路:设置订阅者的优先级,优先级高的接收事件处理,取消事件,事件无法继续往下传递,达到指定接收者的目的。

1.Subscriber Priorities

You may change the order of event delivery by providing a priority to the subscriber during registration.

@Subscribe(priority = 1); //设置优先级
public void onEvent(MessageEvent event) {

}
Within the same delivery thread (ThreadMode), higher priority subscribers will receive events before others with a lower priority. 

2.Cancelling event delivery

You may cancel the event delivery process by calling cancelEventDelivery(Object event) from a subscriber’s event handling method. Any further event delivery will be cancelled: subsequent subscribers won’t receive the event.

// Called in the same thread (default)
@Subscribe
public void onEvent(MessageEvent event){
// Process the event

EventBus.getDefault().cancelEventDelivery(event) ; //取消事件传递
}
Events are usually cancelled by higher priority subscribers. Cancelling is restricted to event handling methods running in posting thread ThreadMode.PostThread.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值