EventBus README

The project's README from github.com/greenrobot/EventBus. As one markdown file: README.md.

EventBus

EventBus is a publish/subscribe event bus for Android and Java.

Build Status Follow greenrobot on Twitter

EventBus...

EventBus in 3 steps

  1. Define events:

    public static class MessageEvent { /* Additional fields if needed */ }
    
  2. Prepare subscribers: Declare and annotate your subscribing method, optionally specify a thread mode:

    @Subscribe(threadMode = ThreadMode.MAIN)  
    public void onMessageEvent(MessageEvent event) {
        // Do something
    }
    

    Register and unregister your subscriber. For example on Android, activities and fragments should usually register according to their life cycle:

     @Override
     public void onStart() {
         super.onStart();
         EventBus.getDefault().register(this);
     }
    
     @Override
     public void onStop() {
         super.onStop();
         EventBus.getDefault().unregister(this);
     }
    
  3. Post events:

     EventBus.getDefault().post(new MessageEvent());
    

Read the full getting started guide.

There are also some examples.

Note: we highly recommend the EventBus annotation processor with its subscriber index. This will avoid some reflection related problems seen in the wild.

Add EventBus to your project

Available on Maven Central.

Android projects:

implementation("org.greenrobot:eventbus:3.3.1")

Java projects:

implementation("org.greenrobot:eventbus-java:3.3.1")
<dependency>
    <groupId>org.greenrobot</groupId>
    <artifactId>eventbus-java</artifactId>
    <version>3.3.1</version>
</dependency>

R8, ProGuard

If your project uses R8 or ProGuard this library ships with embedded rules.

For more details please check the EventBus website. Here are some direct links you may find useful:

Features

Documentation

Changelog

FAQ

License

Copyright (C) 2012-2021 Markus Junginger, greenrobot (https://greenrobot.org)

EventBus binaries and source code can be used according to the Apache License, Version 2.0.

Other projects by greenrobot

ObjectBox (GitHub) is a new superfast object-oriented database.

Essentials is a set of utility classes and hash functions for Android & Java projects.

EventBus (greenrobot/EventBus)

events
Searching Database…

24.7K ·GitHub
What is this?EventBus is a publish/subscribe event bus for Android and Java. It simplifies communication between components — Activities, Fragments, Threads, Services — and decouples event senders from receivers.
So it's a library I add to my app, not a framework that takes it over?A library: the whole jar is tiny (~60k). You plug it into your existing Android or Java project wherever components need to talk to each other.
How do I use it in my app?Three steps: define event classes; declare and annotate subscriber methods (optionally with a thread mode) and register/unregister them — on Android usually along the Activity or Fragment lifecycle; then post events.
How do I add it to my project?The README includes ready dependency snippets for Android and plain Java projects. If you use R8 or ProGuard, there is nothing extra to configure — the needed rules ship embedded.
Any gotchas to watch out for?Yes — the README strongly recommends using the EventBus annotation processor with its subscriber index, which avoids reflection-related problems seen in the wild.
Why use an event bus instead of components calling each other directly?Direct wiring creates tight, error-prone dependencies and life cycle headaches. EventBus decouples senders from receivers, sidesteps those life cycle issues and keeps your code simpler.
What can it do beyond basic publish and subscribe?It has advanced features like delivery threads (subscriber methods can run on a thread mode you choose) and subscriber priorities, so you control how and in what order events are delivered.
Will it weigh down my app?The README bills it as fast, with solid performance across Activities, Fragments and background threads — and the whole thing is a ~60k jar.
Is it proven in real apps?Yes — the README says it is proven in practice by apps with 1,000,000,000+ installs, and the project has been around since 2012.
Creator
greenrobot
Size
1.7 MB
Stars
24.7K
Age
14y
Commits · 90 Days