Questions tagged [greenrobot-eventbus]

EventBus is an Android optimized publish/subscribe event bus that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.

EventBus is an Android optimized publish/subscribe event bus. A typical use case for Android apps is gluing Activities, Fragments, and background threads together. Conventional wiring of those elements often introduces complex and error-prone dependencies and life cycle issues. With EventBus propagating listeners through all participants (e.g. background service -> activity -> multiple fragments or helper classes) becomes deprecated. EventBus decouples event senders and receivers and thus simplifies communication between app components. Less code, better quality. And you don't need to implement a single interface!

General Usage and API:

In EventBus, subscribers implement event handling methods and register themselves to the bus. Posted events are delivered to matching event handling methods based on their event type (the Java class/interfaces implemented by the event).

Using EventBus takes four simple steps:

  1. Implement any number of event handling methods in the subscriber:

    public void onEvent(AnyEventType event) {}

  2. Register subscribers:

    eventBus.register(this);

  3. Post events to the bus:

    eventBus.post(event);

  4. Unregister subscriber:

    eventBus.unregister(this);

More info: https://github.com/greenrobot/EventBus

247 questions
1
vote
0 answers

EventBus: Two subscribers: No subscribers registered for event class org.greenrobot.eventbus.NoSubscriberEvent

AndroidStudio 3.1.2, Gradle 4.5, In my app/build.gradle: implementation 'org.greenrobot:eventbus:3.0.0' Here my MainActivity: public class MainActivity extends AppCompatActivity { @Override public void onStart() { super.onStart(); …
Alexei
  • 14,350
  • 37
  • 121
  • 240
1
vote
1 answer

Guava's EventBus - visibility of @Subscribe

Annotation from interface methods are not inherited to objects implementing that interface, afaik. SO search results. I wanted to use an interface together with Guava's EventBus, which requires that an object has a callback method annotated with…
Moritz
  • 1,085
  • 1
  • 8
  • 20
1
vote
2 answers

Eventbus index doesn't get generated on Android

I tried to follow the steps in http://greenrobot.org/eventbus/documentation/subscriber-index/ but for some reason the MyeventBusIndex simply doesn't get generated! Are there any reasons why that is the case for me?? android { compileSdkVersion…
Zhen Liu
  • 7,550
  • 14
  • 53
  • 96
1
vote
1 answer

What is the difference between observer(design pattern), eventbus(greenroboto), LiveData(Android)?

I'm unable to distinguish what to use. It seems are all working in a same way but different way but the base logic are same, kindly let me know what is the main difference in all?
1
vote
0 answers

About the statement in the EventBus documentation?

i am a beginner of EventBus. I tried to understand the statement in documentation with my program. But it doesn't like what you said in the documentation. Documentation as follows: ...... For example if you post another event in an event handler…
1
vote
2 answers

Eventbus event subscribers

I was learning Event bus(http://greenrobot.org) in android and i have following code public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { …
scott
  • 3,112
  • 19
  • 52
  • 90
1
vote
1 answer

EventBus - Class not recognizing @Subscribe annotation

I don't understand, I'm already using the library on other projects and it's working fine.! and I double check the code and it's the same, but this one is just not working.!? ERROR java.lang.RuntimeException: Unable to start activity…
1
vote
1 answer

EventBus: all child classes receive event

I have BaseActivity with fun onEvent(event: MyEvent) and 4 activities that extend the BaseActivity. My problem is that BaseActivity handles all the events. That means when an event is sent, it is received by all subclasses of BaseActivity that are…
Sermilion
  • 1,920
  • 3
  • 35
  • 54
1
vote
2 answers

subscriber does not get posted message from eventBus

I want to use eventbus into my app. for that I add eventbus lib to my gradle.then I have created a class like this: public class UserEvent { private User eUser; // esup user model private String domain; private String securitySrv; private Cookie…
Cyrus the Great
  • 5,145
  • 5
  • 68
  • 149
1
vote
1 answer

EventBus annotation processor won't accept ThreadMode.MAIN_ORDERED in AndroidStudio 3.1

I'm using AndroidStudio 3.1 Canary 3 at the moment along with D8. I've tried without D8 and have tried 3.1.0 also. The consistent issue is that MAIN_ORDERED throws an error in the annotation processor where it can't find the ENUM. However, when I…
1
vote
2 answers

Call same fragment with different data

I have a Fragment in which I display a response which is the details of a user, and that response contains information about other users(same json structure) and clicking on that link I inflate the same fragment(with different instance) which…
Ankit Khare
  • 1,345
  • 11
  • 30
1
vote
0 answers

ThreadEnforcer usage in Event Bus register method

can anyone simplify what this code does to register an object to able to listen to events posted by the event bus? Also, do you need to wrap the post call in a handler to contact the UI thread ?? The main question is what is the thread enforcer…
Ankit Goel
  • 347
  • 1
  • 3
  • 13
1
vote
1 answer

ProGuard configuration of greenrobot event bus

I'm using eventbus into my application and it's working fine on debuge mode but not working on release APK. Following code used for ProGuard configuration : -keepattributes *Annotation* -keepclassmembers class ** { …
1
vote
1 answer

EventBus multiplying messages by count of Activities

I'm using greenrobot EventBus and have some misunderstandings how to use it. In my app, I have 4 activities: MainActivity and 3 other. Each Activity have it's own role in app, and MainActivity holds connection via COM port and sends/receives…
Mattue
  • 21
  • 6
1
vote
1 answer

How to use network communication using greenrobot eventbus?

So , I would like to use the following feature mentioned on GreenRobots website, EventBus can handle threading for you: events can be posted in threads different from the posting thread. A common use case is dealing with UI changes. In Android, UI…