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
2
votes
1 answer

Rebus - how to register an instance of a handler

I'm trying to use Rebus in C# as an alternative to Java's org.greenrobot.eventbus.EventBus. Can't figure out how to register an isntance of a handler dynamically. Goal: Start the bus Register handler isntances dynamically at runtime (e.g. add new…
Dmitry Avtonomov
  • 8,747
  • 4
  • 32
  • 45
2
votes
2 answers

EventBus - some trouble with event lifecycle

I have a situation where I use this Library greenrobot/EventBus to save data and pass them on different activities. In this case i use EventBus to pass "order" and "cartItems" OBJECT CustomModel from some activities in a joint activity. In this…
2
votes
1 answer

org.greenrobot.eventbus.EventBusException its super classes have no public methods with the @Subscribe annotation

I'm using EventBus to control status of mediaplayer , but I'm running into an error during execution. Caused by: org.greenrobot.eventbus.EventBusException: Subscriber class maa.MainActivity and its super classes have no public methods with the …
2
votes
1 answer

Event Bus Sticky Event

I have a question regard Android EventBus events. Is there any meaning to annotate an event bus subscriber callback method with sticky = true if the event was posted as none sticky? I've used eventBus.post(new MyEvent()) and not…
Moti Bartov
  • 3,454
  • 33
  • 42
2
votes
2 answers

Trying to impact RecyclerView items via EventBus

I'm trying to post an EventBus event from an recycler item view class and subscribe to it in the same class so that the event is grabbed by ALL the recycler items. Now in more detail: I have a RecyclerView where each item (FriendListItem.kt) has a…
Ambran
  • 2,367
  • 4
  • 31
  • 46
2
votes
1 answer

Eventbus onMessageEvent not getting called

I have implemented EventBus in my project but I am not getting all of my events public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { …
2
votes
1 answer

Is EventBus good for communication from RecyclerView adapter to a fragment which is using the RecyclerView

I am using a RecyclerView to show list of videos and on clicking any video the videoplayer starts the video and player has custom controls one which is next and previous and on clicking them RecyclerView gives the next or previous video. So here I…
2
votes
1 answer

EventBus post and subscribe in the same fragment

I have a fragment that makes the data synchro with a remote server, I need to send various distinct objects instances and it must run in the background so I implemented an AsyncTask per object. In this Asynctask I prepare data to be sent to a remote…
2
votes
1 answer

Android : Notified when all Async calls are completed

I am stuck in one implementation. I am developing an Android application, into which I integrated 3rd party SDK (library) and calling its APIs. Function calling of SDK is actually Async calls (WebAPI calls called by the library) which gives a…
2
votes
2 answers

EventBus comunication between activity and service

I'm working on an Android application with EventBus library. I have an activity and a service. I want to to fire an event from activity and receive it on service. The activity is: public class MainActivity extends AppCompatActivity { public…
xcesco
  • 4,690
  • 4
  • 34
  • 65
2
votes
2 answers

Subscriber class and its super classes have no public methods with the @subscribe annotation

I'm implementing EventBus lib to pass and get data from any class or fragment and also subscribed an method to get instant changed data... But I got the following error message: org.greenrobot.eventbus.EventBusException: Subscriber class…
user7113784
2
votes
1 answer

Subscribe and Publish Same event from same class

I am using Greenrobot EventBus 3.0.0. I have a class A and it received an Object Event.In class A I modified that object and pass it to next Activity B. @Override protected void onStart() { super.onStart(); …
Meonix
  • 33
  • 6
2
votes
2 answers

how to identify caller for eventbus on activity class

i am using EventBus on activity and override one event ABC. now i am calling that event from multiple classes (EventBus.getDefault().post(new ABC()) etc.) and i am getting callback on my activity class. so my question is : is there any way to…
2
votes
1 answer

Android Listen to events from Library Module

I am creating a library on Android using EventBus. I am posting an event in my library. EventBus.getDefault().post(new ConnectToDataEvent(Constants.AUTH,true)); The app module is registered to listen for events. @Override public void onStart() { …
user2536851
  • 314
  • 3
  • 11
2
votes
4 answers

EventBus confusion

I'm trying to send a list of objects from ActivityTwo to MainActivity I have followed EventBus's get started page and called register() and unregister() methods from onStart and onStop, then i used EventBus.getDefault().post() to send the data. On…
124697
  • 22,097
  • 68
  • 188
  • 315