1
0
Fork
You've already forked EventBus
0
No description
  • Java 95.5%
  • CSS 4.5%
Find a file
2022年07月11日 10:00:08 +02:00
.github/workflows CI: use temurin for JDK, update checkout and setup-java to v3. 2022年07月11日 10:00:08 +02:00
EventBus fix typo 2022年01月25日 08:53:40 +01:00
eventbus-android Fix ProGuard rules to keep default failure event class constructor. 2021年12月08日 09:36:41 +01:00
EventBusAnnotationProcessor Make group and version detectable by publish plugin. 2021年11月30日 14:34:21 +01:00
EventBusPerformance Make EventBusPerformance build again (project outdated though) 2021年12月08日 10:12:43 +01:00
EventBusTest Re-add deprecated test classes for Android. 2021年06月22日 15:45:24 +02:00
EventBusTestJava Drop AndroidComponentsAvailabilityOnJavaTest, ensured implicitly by other tests. 2021年07月13日 14:47:24 +02:00
EventBusTestSubscriberInJar Update Java test projects. 2021年06月22日 15:35:19 +02:00
gradle Actually sign new artifacts from mavenJava publication. 2021年11月30日 13:36:19 +01:00
javadoc-style travis: build-tools-23.0.2, JavaDoc css 2016年02月04日 21:33:02 +01:00
.gitignore added gradle.properties to .gitignore again after merge 2015年11月06日 20:38:46 +01:00
build.gradle Prepare release 3.3.1 2021年12月08日 11:51:14 +01:00
COMPARISON.md prepping v3.0.0 2016年02月01日 22:04:39 +01:00
CONTRIBUTING.md https 2020年02月10日 17:36:34 +01:00
EventBus-Publish-Subscribe.png improved documentation, added publish/subscribe picture 2014年11月08日 00:31:55 +01:00
gradlew Update Gradle [6.7.1 -> 6.8.3] 2021年06月21日 15:03:18 +02:00
gradlew.bat Update Gradle [6.7.1 -> 6.8.3] 2021年06月21日 15:03:18 +02:00
LICENSE improved documentation, added publish/subscribe picture 2014年11月08日 00:31:55 +01:00
README.md README: fix subscriber method snippet. 2021年12月13日 12:53:39 +01:00
settings.gradle Rename EventBus project so it is added as dependency in POM. 2021年06月22日 14:38:29 +02:00

EventBus

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

Build Status Follow greenrobot on Twitter

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 (~60k jar)
  • is proven in practice by apps with 1,000,000,000+ installs
  • has advanced features like delivery threads, subscriber priorities, etc.

EventBus in 3 steps

  1. Define events:

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

    @Subscribe(threadMode=ThreadMode.MAIN)publicvoidonMessageEvent(MessageEventevent){// Do something}

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

    @OverridepublicvoidonStart(){super.onStart();EventBus.getDefault().register(this);}@OverridepublicvoidonStop(){super.onStop();EventBus.getDefault().unregister(this);}
  3. Post events:

    EventBus.getDefault().post(newMessageEvent());

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.