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

Android EventBus - Unregister from a specific event

I am using EventBus in my Android application and I am trying to unregister from a specific event while keep being registered to other events. It looks like the unregister method only takes the subscriber as a parameter, and not also the event. I…
Cosmin
  • 2,840
  • 5
  • 32
  • 50
2
votes
2 answers

How to receive event in an Intent service (Greenrobots Event Bus)

I am trying to receive a sticky event in an IntentService. I have tried catching the events in onEvent()and onEventBackgroundThread() but I don't receive events. I know how to send and receive events between activities and fragments unable to get…
iZBasit
  • 1,314
  • 1
  • 15
  • 30
2
votes
1 answer

Getting mixed data when using EventBus in a ViewPager

I am using EventBus to post the result to a fragment when an http request is made successfully. This works nice when there's a one subscriber and one publisher relation. However, in my application I have a screen that uses a ViewPager with tabs.…
VCODE
  • 535
  • 5
  • 19
2
votes
0 answers

No subscribers registered for event class error - Greenrobot

I am getting this warning and the code written in my event subscriber is not triggered always.. it is very random. Can someone help me with this. Thanks. I have this class which posts the event... EventListAdapter: protected void…
2
votes
6 answers

Service - Fragment communication

An Activity contains a Fragment which in turn contains a child Fragment, which requests a Service. The app tries to implement dobjanschi rest architecture. When the Service is done working it has to propagate operation result. I tried using a …
2
votes
1 answer

GreenRobot EventBus crash app

I use GreenRobot's EventBus all over my app and love it. When I use a method like public void onEventMainThread(SearchStartedEvent e) { doThis(); } and in doThis() there is an Exception like a NPE, the App won't crash but EventBus will…
fweigl
  • 21,278
  • 20
  • 114
  • 205
1
vote
1 answer

Android EventBus - Sequence for receiving message

I am using EventBus in my application, in which I have one question how it will execute? I have registered receiver in application, activity and fragment What I want in app: Receive message in application class and make some modification and then…
Lalit Jadav
  • 1,409
  • 1
  • 15
  • 38
1
vote
2 answers

How does fragment's lifecycle works inside viewpager? Why onStop is not called on navigation change?

I'm using ViewPager 2 from AndroidX with 4 instances of the same fragment. My question is pretty straight forward. When I'm navigating to some another fragment(using navigation drawer or even something else). OnStop() , OnDestroy(), OnDettach() of…
1
vote
1 answer

With two fragments on one screen (activity), how can one fragment update the other with EventBus

Ok, so I'm new to android development. I'm making a recording app. On the same screen as the recording button (to record things) I also have a Fragment to show how many recordings I have. I can tap the recording button to make a recording, but the…
1
vote
3 answers

Green Robot Event Bus Post and Get ArrayList NPE

I have a fragment ui which has a recyclerview-checkbox list. This fragment is part of a tablayout of two tabs hosted in a dialog fragment. The hosting fragment contains a button from which the ids/names of the checked recyclerview items are…
1
vote
1 answer

No subscribers registered for event class between fragments in EventBus

I'm trying to use the GreenRobot EventBus between two fragments, but I have still No subscribers registered for event class. In my case I have two fragments in bottom navigation bar and there is no any buttons. So I'm clicking the icon on bar and…
user9897182
  • 255
  • 5
  • 18
1
vote
1 answer

Been looking at lot of third party library codes lately and see this code which is confusing me

So here is the piece of code from EventBus getDefault() static method which returns static instance of EventBus class. /** Convenience singleton for apps using a process-wide EventBus instance. */ public static EventBus getDefault() { EventBus…
Amit Bhandari
  • 3,014
  • 6
  • 15
  • 33
1
vote
1 answer

Android - I can't get any result from RX in Kotlin instead EventBus

I am using java and Kotlin in my project and I am using from EventBus but don't work in Kotlin because I am using RX between Java code and Kotlin instead EventBus but don't get any result in Kotlin class. My code is like bellow: object EventBusTest…
jo jo
  • 1,758
  • 3
  • 20
  • 34
1
vote
1 answer

How do I send data from Fragment to Fragment with EventBus?

I am using EventBus to send the long value from a fragment to another fragment. I use the following code to do that. But for me, it doesn't work. What did I do wrong? This is the fragment where I save the…
fatih
  • 1,285
  • 11
  • 27
1
vote
2 answers

EventBus send empty class

In my android app I use org.greenrobot.eventbus.EventBus; 1.I create event: public class NotLoginEvent { } In my fragment send this event: EventBus.getDefault().post(new NotLoginEvent()); And in activity I receive this event: …
Alexei
  • 14,350
  • 37
  • 121
  • 240