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
3
votes
0 answers

Is Thread + EventBus a good alternative over AsyncTask + Handler for REST api calls?

Our app needs to hit some REST services for data (less than 500KB mostly). I was analyzing what should be the best approach for handling the api calls. Possible options were: AsyncTask (seemingly the right candidate as per the Google docs.) Thread…
3
votes
1 answer

GreenRobot: EventBus's isRegistered() method not working as expected

I am using EventBus for receiving the events. I want to check if my Activity is already registered or not as I need to register only once through the whole lifetime of the application, but the issue is that wheneven I come to that Activity which is…
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
3
votes
2 answers

EventBus: Registering without any @Subscribe annotated method

I have a BaseFragment class which registers/unregisters itself to EventBus in onStart()/onStop(), and several child classes that inherit from it (FragmentA, FragmentB...). The base class doesn't have any methods annoted with @Subscribe, and…
Mickäel A.
  • 9,012
  • 5
  • 54
  • 71
3
votes
1 answer

GreenRobot EventBus, ClassNotFoundException still there after using Subscriber Index

I have the common "ClassNotFoundException" issue EventBus with a 4.4.2 device, It's even troubleshot in the FAQ I first double checked that I didn't use any unapropriated lifecycle methods but I didn't. Then I updated to EventBus 3.0.0, and used…
Renaud Favier
  • 1,645
  • 1
  • 17
  • 33
3
votes
1 answer

EventBus Producer has been invalidated and can no longer produce events

I am using RxBus which is an RxJava clone of Otto/EventBus to communicate between the different components of my android app. The app works fine on my Motorola Moto x 2013 running ICS, without crashes. But on a Nexus 5X, running Android M, it throws…
Bubunyo Nyavor
  • 2,511
  • 24
  • 36
3
votes
0 answers

why is EventBus significantly faster while it compare with otto

Both EventBus and Otto are event bus, and I found EventBus has this conclusion: Benchmark results indicate that EventBus is significantly faster in almost every scenario: here is origin page My question is why EventBus is more faster than Otto. I…
xxxzhi
  • 471
  • 3
  • 12
3
votes
2 answers

Are EventBus sticky events automatically removed on the subscriber method?

I'm using GreenRobot's EventBus version 3.0. And there's a section on the docs which says that we can post sticky events, and to receive those events we have to subscribe like this: @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) public void…
Mauker
  • 11,237
  • 7
  • 58
  • 76
3
votes
2 answers

EventBus exception when proj is built - Subscriber class has no public methods called onEvent

So, my app exchanges messages from/to my MainActivity to/from a background Service and I used EventBus to handle that. I'm registering both components with EventBus.getDefault().register(this); on their onCreates. And I'm sending/receiving an…
Teo Inke
  • 5,928
  • 4
  • 38
  • 37
3
votes
4 answers

Difficulty in understanding complex multi threading in Android app

I have big problem with understanding multi threading in my application and because of that finding a bug. I've checked I think all possibilities and still I am getting various (sometimes unexpected) errors. Maybe someone here will be able to advice…
3
votes
1 answer

Sticky events should remain after app close GreenRobot Eventbus

Using StickyEvents from GreenRobot - EventBus they don´t stay in memory after I close the app (showing the running apps and then slide to remove it from there) or after I run a new build from Android Studio. I mean onEventMainThread is not called…
Daniel Gomez Rico
  • 15,026
  • 20
  • 92
  • 162
3
votes
1 answer

Different sqlite databases for testing and actual use in android app

Disclaimer - I have used GreenDAO ORM for creating and managing the sqlite db from within my android app. For my android app, while writing unit tests, I wish to tell the app to switch to using a certain db which is different from the normal one in…
mithril
  • 557
  • 1
  • 6
  • 10
3
votes
1 answer

Greenrobot EventBus Could Not Dispatch Event

I am using EventBus to communicate from a long running thread to Fragments that update their UI. This long running thread is basically listening for network activity, parsing it and putting events on the bus. I have 2 Fragments set to receive the…
3
votes
1 answer

How to use the EventBus onEvent method?

I'm using EventBus in my Android application. In my mainActivity, I have this handler method which sends live data to the EventBus as follows: private final Handler handler = new Handler() { @Override public void handleMessage(Message msg)…
mokko211
  • 597
  • 2
  • 9
  • 25
3
votes
1 answer

Greenrobot's EventBus on a normal Java application

I've been developing Android apps and I've been using Greenrobot EventBus, you can find it here, and I really like it. Clean, versatile and easy to use. Now I'm creating a Java Application and if I use an event bus it will help me a bit. So I…
dazito
  • 7,740
  • 15
  • 75
  • 117
2
votes
1 answer

java.lang.RuntimeException: It looks like you are using EventBus on Android, make sure to add the "eventbus" Android library to your dependencies

I am a fan of this eventbus library and used that on the other projects well without getting any issues. But now, I am getting some odd issue with registering eventbus on the activity and got stuck with this part here... java.lang.RuntimeException:…
LoveMob
  • 46
  • 7