EvenBus3.0中文翻译(二)Priorities and Event Cancellation
来源:互联网 发布:如何卸载mac上的app 编辑:程序博客网 时间:2024/06/09 03:08
水平有限,仅供参考
原文地址
Priorities and Event Cancellation
重点与事件取消
While most use cases of EventBus do not need priorities nor event cancellation,
they may come in handy in some special cases. For example,
an event may trigger some UI logic if the app is in the foreground,
but react differently if the app is currently not visible to the user.
虽然EventBus 大多数情况下不需要优先级或者取消,但是他们可能会在特殊场景用到。
例如,如果APP程序是正在前台展示,这个事件可能会引起一些UI界面的变化,
但是,APP程序处于后台不可见,又会引起不同的反应。
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. The default priority is 0.
在同一个线程模式(ThreadMode)里,
优先级高的订阅者将比优先级低的订阅者优先接收到事件。默认优先级为0。
Note: the priority does NOT affect the order of delivery among subscribers with different ThreadModes!
注:优先级并不能影响到不同线程模式(ThreadMode)里面的订阅者!
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.
你可以通过调用订阅者的事件处理方法cancelEventDelivery(Object event)取消事件传递过程。
任何进一步的事件传递都将被取消:随后的订阅者将无法接收到事件。
// Called in the same thread (default)// 在同一线程中(默认)@Subscribepublic 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.
事件通常被优先级高的订阅者取消。事件取消方法仅限于运行在发布线程ThreadMode.PostThread。
- EvenBus3.0中文翻译(二)Priorities and Event Cancellation
- EvenBus3.0中文翻译(四)Sticky Events
- EvenBus3.0中文翻译(三)Delivery Threads (ThreadMode)
- EvenBus3.0 中文翻译(-)How to get started with EventBus in 3 steps
- pthread_create and priorities pthread_attr_setschedparam
- rsyslog facilities and priorities
- TBB之Exceptions and Cancellation
- security information and event management 学习初探(二)
- android——EvenBus3.0详细使用指南
- android——EvenBus3.0详细使用指南
- Event对象(二)
- Event使用(二)
- Selenium with Python中文翻译(二)
- pthread 简要使用指南(四) Cancellation Points
- Active noise cancellation: Trends, concepts, and technical challenges
- RFC791中文翻译二(dlmu2001)
- RFC793中文翻译二(dlmu2001)
- 初学事件Event(二)
- JS 学习笔记
- Android 百度鹰眼轨迹SDK(v2.1.6)
- Java中自定义Exception异常
- 代码自动生成-宏递归思想
- 找工作——jvm复习(二)
- EvenBus3.0中文翻译(二)Priorities and Event Cancellation
- LeetCode 15 3Sum(尺取法或哈希)
- C++作业2
- YII通过db执行sql语句可以看下面
- leetcode——326——Power of Three
- 多窗口切换及警告框
- android SpannableStringBuilder
- 缓存淘汰算法--LRU算法
- linux下内存的统计和内存泄露类问题的定位