eventbus指定接收者
2016-07-28 23:50
113 查看
http://greenrobot.org/eventbus/documentation/priorities-and-event-cancellation/
思路:设置订阅者的优先级,优先级高的接收事件处理,取消事件,事件无法继续往下传递,达到指定接收者的目的。
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.
思路:设置订阅者的优先级,优先级高的接收事件处理,取消事件,事件无法继续往下传递,达到指定接收者的目的。
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.
相关文章推荐
- linux文件管理 cp mv mkdir rm rmdir
- IDF/Web/不难不易的js加密
- 《前端开发修炼之道》
- JSONP
- java位运算实现加减取模
- Fork/Join的一些好的文章
- 从0开始学习 GitHub 系列之「08.如何发现优秀的开源项目」
- Hbase原理详解
- 背景色及色彩搭配方案推荐
- 组合模式(composite)
- JavaScript实用技巧
- linux文件管理 练习
- MongoDB常用操作命令大全
- Leetcode 216. Combination Sum III (Medium) (cpp)
- tp基础补充
- 网页中插入视频的方法----腾讯、优酷为例
- java四大域总结
- PHP的魔法方法__set() __get()
- Mac OS X安装 ffmpeg
- java实例--海盗的最优方案