EventBus还支持发送黏性事件。何为黏性事件呢?简单讲,就是在发送事件之后再订阅该事件也能收到该事件,跟黏性广播类似。
看看官网的描述
Some events carry information that is of interest after the event is posted. For example, an event signals that some initialization is complete. Or if you have some sensor or location data and you want to hold on the most recent values. Instead of implementing your own caching, you can use sticky events. EventBus keeps the last sticky event of a certain type in memory. The sticky event can be delivered to subscribers or queried explicitly. Thus, you don’t need any special logic to consider already available data.
直接翻译:
一些事件进行信息感兴趣的事件后发布。 例如,一个事件信号,一些初始化完成。 或者如果你有传感器位置数据和你想抓住最近的值。 而不是实现自己的缓存,您可以使用黏性的事件。 EventBus保持过去的事件的特定类型在内存中。

本文详细介绍了EventBus中的黏性事件概念及其应用场景。黏性事件允许在事件发送后订阅仍能接收到该事件,类似于Android中的黏性广播。文章通过实例展示了如何使用黏性事件,并提供了获取和删除黏性事件的方法。
4403

被折叠的 条评论
为什么被折叠?



