explaingit

greenrobot/eventbus

24,729JavaAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

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.

Mindmap

mindmap
  root((eventbus))
    What it does
      Publish events
      Subscribe receivers
      Switch threads
    Key concepts
      Post event
      Subscribe method
      Sticky events
    Use cases
      UI updates
      Service to Activity
      Decoupled modules
    Audience
      Android devs
      Java devs
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Update an Android UI from a background network thread without writing manual threading or Handler code.

USE CASE 2

Let multiple Activity and Fragment screens react to the same app event without coupling them together.

USE CASE 3

Replace complex callback chains in your Android app with clean, type-safe event subscribers.

USE CASE 4

Post a single event from a background service and have it automatically received by every subscribed component.

Tech stack

JavaAndroidGradleMaven

Getting it running

Difficulty · easy Time to first run · 5min
Apache 2.0, use freely for any purpose including commercial projects, just keep the copyright notice.

In plain English

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.

Copy-paste prompts

Prompt 1
Show me how to set up EventBus in an Android app so a background network thread can post an event that updates the UI in MainActivity.
Prompt 2
How do I use EventBus sticky events so a newly launched Activity still receives an event that was posted before it started?
Prompt 3
Write an EventBus subscriber that runs on the main thread and refreshes a RecyclerView when a data-updated event is posted from a background service.
Prompt 4
How do I use EventBus subscriber index generation in a production Android app to avoid reflection overhead and speed up startup?
Prompt 5
How do I unregister an EventBus subscriber in onStop so I don't get events when my Activity is in the background?
Open on GitHub → Explain another repo

← greenrobot on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.