EventBus sticky post 调用一次

EventBus sticky post calls once

我使用 greenrobot 作为 eventbus 到 post 一些粘性 events.everything 工作正常,当我打开应用程序时前任显示的内容表明 sticky post 工作正常。

但是当我关闭应用程序并打开它第二次、第三次……时,没有前任。显示的内容意味着粘性事件还没有被 posted。Sticky 事件只被 posted 一次!为什么?是正常还是bug?

我在 AsyncTaskonPostExecute 中使用下面的代码。

EventBus.getDefault().postSticky(new SliderBusModel(SlideID,SlideImage,SlideType,SlideTitle));

根据文档,只有最后一个粘性事件保留在内存中,直到您通过调用 removeStickyEvent(stickyEvent) 手动删除它,即一次只有一个粘性事件会保留在内存中。如果您的内存中已经有一个粘性事件并且您 post 另一个粘性事件,那么前一个将丢失。如果您现有的事件被其他事件删除,请检查您的代码。阅读下文:

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. So EventBus keeps the last sticky event of a certain type in memory. Then the sticky event can be delivered to subscribers or queried explicitly.