Search code examples
javaandroideventsbus

EventBus sticky post calls once


I use greenrobot as eventbus to post some sticky events.everything works fine and when I open application the ex. content is showed which shows sticky post is working fine.

But when I close app and open it for second,third,... time there is no ex. content showed which means sticky event hasn't been posted.Sticky event get posted only once! why? Is it normal or is a bug?

I use the code below in onPostExecute of AsyncTask.

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

Solution

  • As per document, only last sticky event remain in the memory until you manually remove it by calling removeStickyEvent(stickyEvent)i.e. only one sticky event will remain in memory at one time. If you already have one sticky event in the memory and you post another sticky event, then previous one will be lost. Check your code if your existing event is getting removed by some other event. Read below:

    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.