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

What's a good way to asynchronously update the progress of ProgressDialog from background thread?

I want to have a Splash screen that has an inderteminate ProgressDialog and its progress gets updated by async calls from within a Presenter class (from MVP architecture). I have a number of API calls to make to my BaaS server and for every…
Felipe Caldas
  • 2,492
  • 3
  • 36
  • 55
0
votes
0 answers

Event bus gives NoClassDefFoundError: android/app/assist/AssistContent error when using onProvideAssistContent for pre MArshmallow devices

While launching my application the event bus service gives an error for java.lang.NoClassDefFoundError: android/app/assist/AssistContent at java.lang.Class.getDeclaredMethods(Native Method) at…
0
votes
1 answer

Event bus for a service

I have a service class that receives a message. Here is the code - public void processJSONMessage(String data) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); TextMessage textMessage =…
0
votes
0 answers

Progress Dialog not showing in Android and Event Bus

I have a problem with a progress dialog that does not appear, I don't know what is wrong with my code. I have a listener with EventBus that open, update or close the progress dialog. I can see createDialog(), updateProgress() and closeDialog() are…
0
votes
1 answer

How can fragment in fragmentStatePagerAdapter get data from Fragment hosting the viewPager?

FragmentHost has ViewPager, and Fragments of viewpager need data from FragmentHost to create their views. How to get the data. The data is custom Class. One way is using Serializable implementation of the custom class. But I want to avoid that, as…
q126y
  • 1,589
  • 4
  • 18
  • 50
0
votes
1 answer

Passing large objects between activities through eventbus android

I am new to EventBus. I want to pass the byteArray to the next activity, I don't want to use intents because the byteArray is large i will end up in out of memory error. I want to pass it through eventbus. While implementing event bus, I am getting…
Sai
  • 15,188
  • 20
  • 81
  • 121
0
votes
4 answers

Can a post be lost while rotating screen?

Is that possible that when I click the button and then after waiting some time (~5sec) rotate the screen the post may be missed, because the activity didn't manage to re-register in time? I believe that I've managed to produce that. But it was like…
Guliash
  • 163
  • 1
  • 8
0
votes
1 answer

GreenRobot EventBus receives mistaken event

I'm trying to use EventBus in my project and i have a problem. I have a super class for fragments with generic EVENT parameter: public abstract class BaseNetworkFragment extends Fragment { //some code @Override …
Nikita
  • 1
  • 1
0
votes
2 answers

AndroidAnnotations - Create Singleton EBean without adding the dependency

I am using androidannotations in an Android project and I have an EBean defined as: @EBean(scope = Singleton) class MyBean { public void someFunction() { } } This bean is created whenever it is first required, that is, whenever I…
Vedavyas Bhat
  • 2,068
  • 1
  • 21
  • 31
0
votes
2 answers

How to prevent EventBus from delivering event to wrong Activity

Suppose our app has 3 activities: A, B and C. And only A is registered to EventBus at onStart() and unregistered at onStop() as explained here, and it has an event handler method: onEvent(X event){...} which navigates the user to C upon receiving of…
atakan
  • 133
  • 1
  • 1
  • 8
0
votes
0 answers

Dismissing progress dialog works in Genymotion emulator but not on real device

I am displaying a progress dialog while some background operation is performed. I am using Eventbus to post back to the fragment that's displaying the dialog. I'm using a variable to hold a reference to the dialog. When I test this program using…
tunneling
  • 527
  • 6
  • 21
0
votes
1 answer

Android EventBus - hasSubscriberForEvent() always return false

As I understand, the method hasSubscriberForEvent(Class eventClass) from EventBus should return true if I'm listening for any Event on this eventClass. But it always returns false, I'm not sure why. In my fragment I register and unregister the…
Bugdr0id
  • 2,962
  • 6
  • 35
  • 59
0
votes
2 answers

GreenRobot Exception : de.greenrobot.event.EventBusException: Invoking subscriber failed

Time to time I get this exception. I just use green-robot the standard way, between views, fragments, activities, services and the app, with the default instance, and time to time some stickyEvents. I did't find any other post that are related to…
Anthony
  • 3,989
  • 2
  • 30
  • 52
0
votes
1 answer

Is it good to replace broadcast sending and receiving the event states with GreenRobot's EventBus from Service to Activity?

This is a follow up from this post How to use GreenRobot's EventBus in broadcasting events from Service to Activity? my use case revolves around a service and an Activity. Service is used for tracking the changes in the BLE connection. Activity is…
0
votes
0 answers

eventbus delay when triggered

I am using Greenbot EventBus in my app and am getting like a 2 second delay when I press a button that fires an event. My EventBus class ResetArmyEven.java public class ResetArmyEvent { } it is triggered here: public void onClick(View v) { …
Ephraim Schmitt
  • 227
  • 2
  • 16