Sticky events should remain after app close GreenRobot Eventbus

♀尐吖头ヾ 提交于 2021-02-19 03:38:06

问题


Using StickyEvents from GreenRobot - EventBus they don´t stay in memory after I close the app (showing the running apps and then slide to remove it from there) or after I run a new build from Android Studio.

I mean onEventMainThread is not called after EventBus.getDefault().registerSticky(subscriber);

Why?


回答1:


EventBus is a runtime construct. Thus, sticky events only exist in memory during the lifecycle of a single run of an application. They can survive configuration changes and even moving the app to the background and back again. But as you found they won't survive a force-quit of an app. If you need an event to survive across application runs, you could theoretically extend the capabilities of EventBus to serialize events and persist them to Shared Preferences or similar. However, this would be stretching the scope of what an EventBus is intended for.



来源:https://stackoverflow.com/questions/30020966/sticky-events-should-remain-after-app-close-greenrobot-eventbus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!