问题
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