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
9
votes
2 answers

What are the disadvantages of subscribing to Eventbus in Application class?

I am using EventBus in my Android application. Is it a good idea to do a Eventbus.getDefault().register(this) in my Application.onCreate() ? I don't have any UI updates to be made. I am trying this to make sure that I receive the subscription data…
dev
  • 11,071
  • 22
  • 74
  • 122
9
votes
5 answers

Events being received multiple times - Greenrobot eventbus

I am using Greenrobot's EventBus in my app, and it works fine. However, if I press the back button to close the app, then restart the app instantly I seem to receive the event twice. If I then do so again, I will receive it three times and so on. I…
Russ Wheeler
  • 2,590
  • 5
  • 30
  • 57
9
votes
3 answers

IPC in Android using GreenRobot eventbus

I need to communicate with a remote service, using (greenrobot) EventBus. Unfortunately, it does not seem to work with IPC. Looking at the code, I don't see a workaround either. Any help would be appreciated ! Bonus question - are there any other…
dev
  • 11,071
  • 22
  • 74
  • 122
8
votes
1 answer

RecyclerView RecyclerViewDataObserver was not registered

Im working with RecyclerView, SyncAdapter and greenrobot eventbus When my SyncAdapter finished syincing i post a message into the message bus: EventBus.getDefault().post(new EventMessagesRefreshed()); In my target class i do the…
Mulgard
  • 9,877
  • 34
  • 129
  • 232
8
votes
1 answer

GreenRobot's eventbus can't see annotation, "no public methods"

So, I found out about Green Robots' eventbus module. Followed the instructions on this page to try to get it working: http://greenrobot.org/eventbus/documentation/how-to-get-started/ Seems simple enough. I put in the appropriate code, but when…
Ken Corey
  • 435
  • 3
  • 15
8
votes
3 answers

Android Event bus does not works with two event listener

In my Android application I have used an Activity and Adapter for list view, my acquirement is need to communicate both adapter class and activity via event listener using EventBus, so that I have created two event listener classes. My process…
M.A.Murali
  • 9,988
  • 36
  • 105
  • 182
8
votes
1 answer

Event bus and lifecycle of android ui components

I have been searching for perfect android application architecture and read a few great blogposts on this topic. 1) http://www.mdswanson.com/blog/2014/04/07/durable-android-rest-clients.html 2)…
Araz Abishov
  • 1,661
  • 3
  • 15
  • 26
8
votes
2 answers

Subscriber class has no public methods called on Event

while using green Robot Eventbus I got an error E/AndroidRuntime(2537): Caused by: de.greenrobot.event.EventBusException: Subscriber class com.example.MyActivity has no public methods called onEvent Details: I'm loading Activity which contains a…
LOG_TAG
  • 19,894
  • 12
  • 72
  • 105
7
votes
2 answers

Eventbus event never gets to the fragment

I have a Fragment A which on a click of a button will start Fragment B that contains a RecyclerView. In Fragment B, on click of an item EventBus is started and that value needs to be passed to Fragment A. But, for some reason, the value never…
Esteban
  • 667
  • 9
  • 22
7
votes
1 answer

Eventbus: Remove sticky event after consuming

I use firebase to send notification. When the app is in foreground, the notification is received by the class that extends FirebaseMessagingService. So in onMessageReceived, I do this: EventBus.getDefault().postSticky(new NotificationEvent(body,…
X09
  • 3,827
  • 10
  • 47
  • 92
7
votes
2 answers

Greenbot Eventbus 3.0: What is the difference between onEvent, onEventMainThread, onEventBackgroundThread and onEventAsync?

I am a bit confused with the usage of onEvent, onEventMainThread, onEventBackgroundThread and onEventAsync in Greenrobot's EventBus 3.0 From what I see in the documentation: onEvent is used with ThreadMode.POSTING (default) onEventMainThread is…
grim
  • 6,669
  • 11
  • 38
  • 57
7
votes
5 answers

Greenrobot EventBus event not received

I'm using Greenrobot EventBus to pass events from one activity to another. The flow is something like this: Activity1 starts -> scan a barcode -> Activity2 starts -> accept or deny the response and send an event to Activity1. So Activity2 sends a…
Alin
  • 1,044
  • 6
  • 20
  • 42
6
votes
2 answers

Fragment does not respond to UI updates and eventbus events after resume

I have a SearchFragment class which extends a class called BaseFragment in which onResume and onStop are overridden as below: @Override public void onResume() { checkEventBusRegistration(); super.onResume(); } @Override public void onStop() { …
6
votes
1 answer

Reducing number of event classes when using EventBus or Otto

I am about to start development on an Android app. I am interested in using Otto or EventBus in my app to assist with making asynchronous REST network calls and notifying the main thread when the calls have returned.The one major flaw with the use…
6
votes
2 answers

Event Bus Fragment Unregister

I've a splashscreen Fragment that is registered to event bus: @Override public void onStart() { super.onStart(); EventBus.getDefault().register(this); } @Override public void onStop() { EventBus.getDefault().unregister(this); …
Jumpa
  • 4,319
  • 11
  • 52
  • 100
1
2
3
16 17