Questions tagged [greenrobot-eventbus-3.0]

EventBus is an open-source library for Android using the publisher/subscriber pattern to solve the problem of loose coupling. EventBus enables central communication to decoupled classes with just a few lines of code – simplifying the code, removing dependencies, and speeding up app development.

EventBus: Events for Android

EventBus is an open-source library for Android using the publisher/subscriber pattern to solve the problem of loose coupling. EventBus enables central communication to decoupled classes with just a few lines of code – simplifying the code, removing dependencies, and speeding up app development. EventBus System

Benefits using EventBus: It…

  1. simplifies the communication between components
    • decouples event senders and receivers
    • performs well with Activities, Fragments, and background threads
    • avoids complex and error-prone dependencies and life cycle issues
  2. is fast; specifically optimized for high performance
  3. is tiny (<50k jar)
  4. is proven in practice by apps with 100,000,000+ installs has advanced features like delivery threads, subscriber priorities, etc.

Further EventBus Features

  • Convenient Annotation based API: Convenient Annotation based API: Simply put the @Subscribe annotation to your subscriber methods. Because of a build time indexing of annotations, EventBus does not need to do annotation reflection during your app’s run time.
  • Android main thread delivery: When interacting with the UI, EventBus can deliver events in the main thread regardless how an event was posted.
  • Background thread delivery: If your subscriber does long running tasks, EventBus can also use background threads to avoid UI blocking.
  • Event & Subscriber inheritance: In EventBus, the object oriented paradigm apply to event and subscriber classes. Let’s say event class A is the superclass of B. Posted events of type B will also be posted to subscribers interested in A. Similarly the inheritance of subscriber classes are considered.
  • Jump start: You can get started immediately – without the need to configure anything – using a default EventBus instance available from anywhere in your code.
  • Configurable: To tweak EventBus to your requirements, you can adjust its behavior using the builder pattern.
59 questions
19
votes
3 answers

Event Bus in Fragment

I have created one Activity (DemoActivity.java) with 2 Fragments (FragmentOne.java and FragmentTwo.java). I registered the EventBus in the Activity like thisEventBus.getDefault().register(this); and created one Suscriber method in the Activity:…
sanil
  • 482
  • 1
  • 7
  • 23
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
6
votes
2 answers

EventBus with Kotlin not working

I am new to Android, and trying to send message from a Fragment to its container Activity using EventBus. However, I am getting error: D/EventBus: No subscribers registered for event class…
Khawar
  • 9,151
  • 9
  • 46
  • 67
5
votes
0 answers

how to pass 'eventBusIndex' parameter to EventBus annotation processor

I am just getting started to use the new Android Jack compiler and use the Greenrobot Eventbus. I got it working after some trial-and-error but it only seems to work, when I specify the eventBusIndex parameter in 2 places - see code below: android…
5
votes
6 answers

Simple EventBus - No subscribers Registered

I'm trying to implement the absolute basic implementation of EventBus Library for Android. What I'm trying to simple input content by user in activity 1 and then instead of intent extras I'm using eventbus to post the entire object to the next…
Abhinav Das
  • 306
  • 1
  • 4
  • 12
5
votes
1 answer

Greenrobot's Eventbus : Two Fragments calling async tasks jobs got Eventbus confused

I am currently working on Fragments that was created under Activities with FragmentPagerAdapter. I used GreenRobot's EventBus 3.0 to return some AsyncTasks I created from a service class. However, since these two fragments are created one after the…
3
votes
1 answer

EventBus in custom view

I'm customing a View and I want to listening event from there. I created a show() and hide() method then put register & unregister inside these methods. But i tried to put public class CalculatorView extends RelativeLayout { ....... public void…
Harry T.
  • 3,478
  • 2
  • 21
  • 41
3
votes
2 answers

Greenrobot Android Eventbus - No option eventbusindex passed to annotation processor

I'm trying to set up a simple subscriber in my Android application using Greenrobot's Eventbus, but I am getting a gradle build error. I have shown my code below. Event class public final class OffersProcessedEvent {} Base Fragment public class…
3
votes
1 answer

Subscribe to different event bus in same class

I am using the GreenRobot Event Bus 3.0 as an event bus and I have 2 publishers: private static final EventBus EVENT_BUS = new EventBus(); //Publish event to the event bus public static void sendEvent(LoggingEvent event){ …
BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
3
votes
3 answers

View pager with multiple fragments - Eventbus get registered multiple times

I used ViewPager with 3 nested Fragment.I used EventBus for event handling. But in my case subscribe method gets called by multiple times. Because EventBus gets register by multiple times. I have used these methods for registeringa nd…
Priya Sasane
  • 103
  • 1
  • 1
  • 6
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
2
votes
0 answers

Multiple instances of the same class getting same event from event bus

I am using greenroot eventbus to pass event payloads between the 2 components of my application in an async manner using the @Subscribe annotation to subscribe to events. The issue is if multiple instances of the class having @Subscribe annotation…
user2565192
  • 694
  • 1
  • 8
  • 19
2
votes
1 answer

Eventbus onMessageEvent not getting called

I have implemented EventBus in my project but I am not getting all of my events public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { …
1
2 3 4