EventBus 3 released, now based on @Annotations

EventBus3
Today, we are pleased to release EventBus 3. Previous versions of EventBus rejected to use annotations for performance reasons. Now, version 3 embraces annotations to improve performance. How does that make sense? Unfortunately, Android’s performance did not get any better. Reflection on annotations is still very bad compared to Desktop Java, even on Android 6 and ART. EventBus 3 resolves this problem by introducing a new annotation processor, which will index all annotations at build time. It generates a class containing all the data that would be expensive to get at run time. Build-time indexing makes EventBus 3 the fastest EventBus ever.

Switching to annotations is a major change and the API is not compatible with previous versions. Also, the package name changed to org.greenrobot.eventbus and the artifact is now org.greenrobot:eventbus. Like this you could even run EventBus 2 and 3 in your app in parallel. If you want to upgrade an existing app to EventBus 3, you need to change the imports to the new package and add @Subscribe annotations to your onEvent methods.

Another benefit of annotations is that each @Subscribe method can now individually configure additional parameters. Previously, priority and stickyness was configured on a class basis only, forcing all onEvent methods to share a single configuration. Now with EventBus 3, the @Subscribe offers additional parameters per method.

EventBus 3 comes with an improved documentation separating topics into individual pages. The getting started guide is good place to learn more details about EventBus 3.

Merken

Merken

Spread the love
Posted in Release and tagged , , , , .

5 Comments

  1. Sorry, but I have n00bish question. What is the different between RxAndroid and EventBus 3 ? EventBus is lighter than Rx ? Can you explain ?

  2. Yes, EventBus is much lighter than Rx. You can do a lot of things with Rx, which you cannot do with EventBus. On the other side, EventBus is very focused and simple to learn. EventBus’ strength over the observer pattern used with Rx is a higher degree of decoupling: with EventBus, it doesn’t matter which component sends the events. Thus, you don’t need to know the event source.

  3. I found out about this library after searching for a replacement for the now deprecated Otto. I love it. Sticky events have solved so many issues that Otto could not. Very well done on an excellent library.

  4. Typo/error in your writing: “Build-time indexing makes EventBus 3 is the fastest EventBus ever.”, extra “is”. Thanks for the great tool, used it for years.

Comments are closed.