EventBus
Event bus for Android and Java that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.
EventBus is a tiny Java and Android library that lets different parts of your app send and receive messages without being directly connected, handling thread switching automatically.
EventBus is a lightweight Java and Android library that lets different parts of an app communicate with each other without being directly connected. It follows a publish-subscribe pattern — one part of your app broadcasts ("posts") an event, and any other parts that have registered interest in that event type automatically receive it. This removes the need to pass data manually through complicated chains of function calls or callbacks.
In practical terms, imagine you have an Android app with multiple screens (Activities and Fragments) and background tasks. Without EventBus, getting a background thread to update the user interface requires careful threading code. With EventBus, the background task posts an event, and any part of the app that subscribes to that event type receives it automatically, with EventBus handling the thread switching for you. You can control which thread the receiver runs on by specifying a thread mode.
Android developers use EventBus to reduce boilerplate code and avoid bugs that arise from complex inter-component dependencies. The library is very small (about 60 kilobytes) and has been used in apps with over a billion installs. It is added to Android or Java projects via Maven or Gradle (standard Java build tools). Built in Java and licensed under Apache 2.0.
Where it fits
- Update an Android UI from a background network thread without writing manual threading or Handler code.
- Let multiple Activity and Fragment screens react to the same app event without coupling them together.
- Replace complex callback chains in your Android app with clean, type-safe event subscribers.
- Post a single event from a background service and have it automatically received by every subscribed component.