With over 25% of the top Android apps using it, EventBus is more popular than ever before. So we’re very happy to announce EventBus 3.1 today. Starting with this release, EventBus works with plain Java (non-Android) projects. This has two major benefits: Firstly, it opens up EventBus for all Java developers and makes it usable for server and desktop applications. Secondly, it allows Android developers to use EventBus in local unit tests. Before, you had to use instrumentation tests which are slow and require a device. In contrast to this, plain Java unit tests are blazingly fast as they run directly on your desktop machine.
The second improvement is a new thread mode: MAIN_ORDERED. It is a variation of the default MAIN thread mode and also ensures event delivery in the main thread. The difference is when an event is posted in the main thread: with MAIN it will pass on the event to subscribers immediately in a synchronous fashion. MAIN_ORDERED will only enqueue the event in the call to post(...) for later delivery to subscribers. This gives event processing a stricter and more consistent order (thus the name MAIN_ORDERED). For example if you post another event in an event handler with MAIN thread mode, the second event handler will finish before the first one (because it is called synchronously – compare it to a method call). With MAIN_ORDERED, the first event handler would finish, and then the second one will be invoked at a later point in time (as soon as the main thread has capacity).
We are considering making MAIN_ORDERED the default in a future version of EventBus. Because MAIN and MAIN_ORDERED behave slightly different, there may be some cases where this also may change an app’s behavior. It’s a trade off in every case: MAIN is faster when events are posted on the main thread and MAIN_ORDERED offers more consistent and predictable event delivery. Let us know what you think about it.
One more thing: we would love to get some feedback on EventBus and how we can further improve it. Our feedback form takes only a minute. Thank you!
4 26 1