Although there are several open source libraries that are able to deliver this kind of pattern in Android, we will base our code examples on the popular event bus library (http://greenrobot.org/eventbus/) since it offers advanced features and high performance.
The high performance library is optimized for the Android OS and it has been used by many popular applications on Google Play.
These are the advanced features delivered by the EventBus
library that you should be aware of:
Annotation-based subscription – You can define an subscription method by annotating an Android
Activity
,Service
, orFragment
instance methodBackground and main thread event delivery – The subscriber could define in which thread the event will be delivered regardless of whether it was generated in a background or main thread
Event and subscriber inheritance – We can construct events or subscribers by extending (Java subclass) other events or subscribers:
class OtherEvent extends MyEvent
No configuration...