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
5
votes
4 answers

Replace LiveData with EventBus in multi activity

Currently my project used EventBus to post event and I am trying to replace LiveData with EventBus. In theory, they work similarly. I migrated without no pain in the beginning. But it comes up a scenario I have no idea how to deal with it. And…
5
votes
1 answer

How to post a message from a background service to a UI fragment?

I have an issue with EventBus from Greenrobot. I was trying to post an event from a background service form my sync adapter and catch it in a fragment to update the UI. The problem is that when I try to post the event from sync adapter I have get…
5
votes
1 answer

Greenrobot's Eventbus : Two Fragments calling async tasks jobs got Eventbus confused

I am currently working on Fragments that was created under Activities with FragmentPagerAdapter. I used GreenRobot's EventBus 3.0 to return some AsyncTasks I created from a service class. However, since these two fragments are created one after the…
5
votes
2 answers

Android: with Greenrobot EventBus how to communicate between 2 Activity?

I would like to communicate between 2 Activity. Both are the register() and the unregister() methods: @Override public void onStart() { super.onStart(); EventBus.getDefault().register(this); } @Override public void onStop() { …
anthony
  • 7,653
  • 8
  • 49
  • 101
5
votes
4 answers

AndroidAnnotations and EventBus

I have an annotated Activity in a library, which is a subscriber to an EventBus event from the same library. It looks something like this, greatly simplified: @EActivity(resName = "activity_foo") public class Foo extends Activity { public void…
Herrbert74
  • 2,578
  • 31
  • 51
5
votes
2 answers

null pointer exception with Fragments and EventBus

I have gone through various methods to make this project work and have finally settled on EventBus from Green Robot. My second question in relation to this on here is here:-Multiple Fragment to Activity communication. I was directed down the Event…
Gary
  • 69
  • 1
  • 9
4
votes
1 answer

How to receive eventbus events when Activity is in the background

I want to get notification message using Firebase Notification service. I'm sending message from Firebase, it is ok. I want to get this notification if user run in MainActivity also I want to show pop-up using dialog. If user run other activities…
4
votes
1 answer

Using bus whenever the view isn't started yet?

I've got this problem since I switched to EventBus (same would occurs with any bus library) where whenever I want to perform an action when the view isn't ready, then I will get the error that the bus isn't registered; E/EventBus: Could not dispatch…
Jaythaking
  • 2,200
  • 4
  • 25
  • 67
4
votes
2 answers

EventBus posting can't update Toolbar Title. Any workaround?

I use EventBus (GreenRobot) to post from backgroundThread to my activity (which is a UiThread). I could start a fragment etc. I also want to update my Title, so I did as below. (calling the Activity setTitle()) @Subscribe public void…
Elye
  • 53,639
  • 54
  • 212
  • 474
4
votes
1 answer

Android :Green robot eventbus : Multiple events received on single post

I am using Green robot event bus in Android I am calling all events using EventBus.getDefault().post and onStop I am calling EventBus.getDefault().unregister(this); in my Activity. However once I press back and reopen the application, on a single…
Jalpesh
  • 1,104
  • 1
  • 13
  • 25
4
votes
2 answers

Multiple sticky objects of the same class?

I'm using sticky events in EventBus to pass my "selected" objects into the upcoming Activity. The detail activity allows the user to "select" another object to fetch a new list. I want to post another sticky event with the same object class again…
4
votes
1 answer

Best practice for eventbus with thread safety

My app has activities for the user interaction and a background service which is the only place where the data model is being modified. The background service listens to actions that where made by the user as well as incoming messages from the…
3
votes
1 answer

GreenRobot EventBus subscribe based on API level

I'm attempting to subscribe to an EventBus event. Due to the parent class not existing in API level 23 and below, I'm in a situation where I need to conditionally subscribe to said event. I realize that, through the use of build variants, it is…
michael
  • 463
  • 3
  • 9
3
votes
1 answer

EventBus in custom view

I'm customing a View and I want to listening event from there. I created a show() and hide() method then put register & unregister inside these methods. But i tried to put public class CalculatorView extends RelativeLayout { ....... public void…
Harry T.
  • 3,478
  • 2
  • 21
  • 41
3
votes
2 answers

Greenrobot Android Eventbus - No option eventbusindex passed to annotation processor

I'm trying to set up a simple subscriber in my Android application using Greenrobot's Eventbus, but I am getting a gradle build error. I have shown my code below. Event class public final class OffersProcessedEvent {} Base Fragment public class…
1 2
3
16 17