Code Monkey home page Code Monkey logo

eventbus's Introduction

EventBus

EventBus is publish/subscribe event bus optimized for Android.

EventBus...

  • simplifies the communication between components
    • decouples event senders and receivers
    • performs well with Activities, Fragments, and background threads
    • avoids complex and error-prone dependencies and life cycle issues
  • makes your code simpler
  • is fast
  • is tiny (<50k jar)
  • is proven in practice by apps with 100,000,000+ installs
  • has advanced features like delivery threads, subscriber priorities, etc.

Build Status

EventBus in 3 steps

  1. Define events:
    public class MessageEvent { /* Additional fields if needed */ }

  2. Prepare subscribers:
    eventBus.register(this);
    public void onEvent(AnyEventType event) {/* Do something */};

  3. Post events:
    eventBus.post(event);

Add EventBus to your project

EventBus is available on Maven Central. Please ensure that you are using the latest version by checking here

Gradle:

    compile 'de.greenrobot:eventbus:2.4.0'

Maven:

<dependency>
    <groupId>de.greenrobot</groupId>
    <artifactId>eventbus</artifactId>
    <version>2.4.0</version>
</dependency>

Or download EventBus from Maven Central

How-to, Developer Documentation

Details on EventBus and its API are available in the HOWTO document.

How does EventBus compare to other solutions, like Otto from Square? Check this comparison.

Additional Features and Notes

  • NOT based on annotations: Querying annotations are slow on Android, especially before Android 4.0. Have a look at this Android bug report.
  • Based on conventions: Event handling methods are called "onEvent".
  • Performance optimized: It's probably the fastest event bus for Android.
  • Convenience singleton: You can get a process wide event bus instance by calling EventBus.getDefault(). You can still call new EventBus() to create any number of local busses.
  • Subscriber and event inheritance: Event handler methods may be defined in super classes, and events are posted to handlers of the event's super classes including any implemented interfaces. For example, subscriber may register to events of the type Object to receive all events posted on the event bus.

FAQ

Q: How is EventBus different to Android's BroadcastReceiver/Intent system?
A: Unlike Android's BroadcastReceiver/Intent system, EventBus uses standard Java classes as events and offers a more convenient API. EventBus is intended for a lot more uses cases where you wouldn't want to go through the hassle of setting up Intents, preparing Intent extras, implementing broadcast receivers, and extracting Intent extras again. Also, EventBus comes with a much lower overhead.

Q: How to do pull requests?
A: Ensure good code quality and consistent formatting. EventBus has a good test coverage: if you propose a new feature or fix a bug, please add a unit test.

Release History, License

CHANGELOG

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

More Open Source by greenrobot

greenrobot-common is a set of utility classes and hash functions for Android & Java projects.

greenDAO is an ORM optimized for Android: it maps database tables to Java objects and uses code generation for optimal speed.

Follow us on Google+ to stay up to date.

eventbus's People

Contributors

greenrobot avatar perfectcarl avatar nbeloglazov avatar leandros avatar jnagels avatar joanzapata avatar mikosik avatar f2prateek avatar stefanhoth avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.