Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EventBus, register and registerSticky method

I use greenrobot EventBus library to send data between two fragments in my android app and I want to know what is the diffeence between register(Object b) method and registerSticky(Object object) method?

like image 552
karoluch Avatar asked Jan 20 '15 17:01

karoluch


People also ask

What is EventBus used for?

EventBus is an open-source library for Android and Java using the publisher/subscriber pattern for loose coupling. EventBus enables central communication to decoupled classes with just a few lines of code – simplifying the code, removing dependencies, and speeding up app development.

What is sticky event?

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.


1 Answers

EventBus allows you to post events that are "sticky" and by that EventBus understands events that "stick to the eventbus" for future access.

If you post a normal event when there are no subscribers registered at the moment of sending, this event will be discarded.

You can post a sticky event though, even if there are no subscribers to receive that at the moment, and it won't be discarded (unless there is another sticky event posted in the future). When a subscriber registers with registerSticky the delivery of the last sticky event is also triggered.

like image 61
Bartek Lipinski Avatar answered Sep 22 '22 13:09

Bartek Lipinski