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

Clear stack activities from specific activity with eventBus

I would like to know if it's possible to clear all activities from an old one. I would like to use enventBus to do this. Example of a stack of activities: startActivity(A) then startActivity(B) then startActivity(C) then…
Johnny
  • 2,989
  • 4
  • 17
  • 28
1
vote
1 answer

Subscribed Events and Polymorphism fire twice

I recently changed my app to be less dependent on other parts of the application by switching to eventbus. Now I am seeing a strange issue, I don't know if its a bug or intended feature of green robot's eventbus. Say I have an Event A and Event B,…
1
vote
1 answer

Android event bus: events fire without waiting for a post

I have a button in my app that starts a custom service class when clicked. Then, when clicked again, I stop the service and display a progress dialog. The onClick of that buttons looks like this: public void onClick(View v) { if…
1
vote
0 answers

How to unit test Retrofit 2.0 api calls along with EventBus with robospock?

Can anyone help me unit testing api calls using retrofit 2.0 and eventBus for managing the response from the api, Specifically using Robospock public boolean login(String username, String password) { Retrofit retrofit = new Retrofit.Builder() …
1
vote
1 answer

crash on Orientation change while filming with Library CWAC CAM2

I've a crash on my nexus 5 Android 6 (hammered/hammered) using CommonsWare library cwac:cam2 when I change the orientation on the recording/photo capturing activities. The bug is systematic on my device. stacktrace : E / AndroidRuntime: FATAL…
Renaud Favier
  • 1,645
  • 1
  • 17
  • 33
1
vote
1 answer

EventBus not working when trying to communicate between two fragments

I have three fragments in a viewpager set up like a sliding tab layout. I need to pass a string value from one fragment to another. First, I tried setting up an interface like the answers here suggest How to pass data between fragments which did…
1
vote
1 answer

EventBus: How to keep track?

I am using an event bus (greenrobot) for communication between fragments and activities. Works great. But one thing I was wondering about: How do people keep track of where these are fired? Example: When I see an onEvent() method somewhere, how…
Jens
  • 6,243
  • 1
  • 49
  • 79
1
vote
3 answers

RxJava and GreenRobot EventBus

I am writing an app that receive calls from JNI to static methods in a Java Class. By example public class Receiver { // method called from C++ in some thread private static void receive(int value) { EventBus.instance().post(new…
1
vote
1 answer

Which one is better Otto or Eventbus ?

I am planning to use event based solution to decouple few aspects in an android Application. This application involves connecting to multiple sockets and receiving events from them asynchronously. I am planning to use Netty NIO for handling these…
praveena_kd
  • 525
  • 5
  • 15
1
vote
2 answers

Eventbus: How to deal with no clear unsubscribe point?

Broad Problem How do you deal with situations where there is no clear place to unsubscribe? Specific Problem In a BroadcastReceiver in Android, there's no end-of-lifecycle method where one can call EventBus's unsubscribe. This BroadcastReceiver can…
Dheeraj Bhaskar
  • 18,633
  • 9
  • 63
  • 66
1
vote
1 answer

Could I use EventBus in Activities communication?

There are three activities A, B, and C Register EventBus in Activity A onCreate(),and unregister on onDestroy(), and a method onEvent(TestEvent e); Activity A starts Activity B Activity B starts Activity C In Activity C: …
Fantasy_RQG
  • 143
  • 1
  • 13
1
vote
0 answers

Calling ".class" on Typed class (e.g. MyClass.class)

I am trying to use a function in GreenRobot's EventBus class: public T removeStickyEvent(@NotNull Class tClass); This works with normal classes such as: MyEvent myEvent = eventbus.removeStickyEvent(MyEvent.class); Now, I would like to get…
bcorso
  • 45,608
  • 10
  • 63
  • 75
1
vote
1 answer

Failed to resolve: 'de.greenrobot:eventbus:2.4.0'

I am using Android Studio but when I try to add: compile 'de.greenrobot:eventbus:2.4.0' to my dependencies in my app component's gradle file, I get a banner: Project sync succeeded. Open the 'Messages' view to see the errors found. And in the…
reubenjohn
  • 1,351
  • 1
  • 18
  • 43
1
vote
1 answer

Eventbus - how to unregister POJO?

How and where should I unregister the EventBus in POJO which is independent from the android lifecycle? (no onCreate-, no onDestroy-method) Thanks in advance
dowjones123
  • 3,695
  • 5
  • 40
  • 83
1
vote
1 answer

Exclude sender from receiving event (Greenrobot's Eventbus)

I have a class which is sender and receiver of objects (of one type) that are put on the Eventbus. Is there a way to exclude the sender from the receiving of the event? I have multiple senders and only want to receive the events from other senders…
Soccertrash
  • 1,830
  • 3
  • 28
  • 48