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
3 answers

EventBus called multiple times in ViewPager Fragment

I have a ViewPagerAdapter like this public class ViewPagerAdapter extends FragmentStatePagerAdapter { List movieCategoryList; public ViewPagerAdapter(FragmentManager fm, List movieCategoryList) { …
0
votes
1 answer

How to send same data from one Fragment to two other different fragments using EventBus 3

I'm using EventBus 3 to send data between Fragments. I have sent data from Fragment A with EventBus.getDefault.post(etc) and successfully receiving data in Fragment B. Now when I try to get the same data of Fragment A in Fragment C. Nothing is…
Ali Khan
  • 61
  • 2
  • 10
0
votes
1 answer

Event Bus called every time on Activity created

I wrote a NetworkStateReceiver for check internet state & publish that intent to Activity via Event Bus. public class NetworkStateReceiver extends BroadcastReceiver { private static final String TAG = "NetworkStateReceiver"; …
0
votes
1 answer

I register object in parent class but subscribe events in child class, yet it still works why?

So this is exactly how I want it to work but I'm just confused on why it works. I register the object in parent class but subscribe events in child class. By registering the object in the parent class, wouldn't EventBus be seeing type parent…
0
votes
1 answer

EventBus: @Subscribe - not receive message

compile 'org.greenrobot:eventbus:3.0.0' Here my frament subscriber: public class FragmentSort extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle…
Alexei
  • 14,350
  • 37
  • 121
  • 240
0
votes
0 answers

Why does the eventbus call subscriber mutiple times?

I use the greenrobot Eventbus for events in my Android app. I registered a subscriber and unregister them accordingly and nevertheless it calls them multiple times. It seems as if they are registered multiple times but they aren't. Also, in the log…
0
votes
0 answers

GreenRobot EventBus data sharing between activities

I have a flow of activities that goes like this: ProductA > CreditCardA > PaymentA > ConfirmationA > DoneA Now, the confirmation screen needs information from ProductA, CreditCardA and PaymentA. However, I don't want to keep passing data that is…
user6046168
0
votes
2 answers

EventBus behavior with Activity/Fragment lifecycle

I have registered my activity/fragment like this: @Override public void onStart() { super.onStart(); EventBus.getDefault().register(this); } @Override public void onStop() { EventBus.getDefault().unregister(this); …
Cícero Moura
  • 2,027
  • 1
  • 24
  • 36
0
votes
1 answer

Change SnackBar BackgroundColor EventBus Exception

The activity receives the event from a Fragment, the activity needs to create a snackbar and change the background of the snackbar. But in doing so the error in the log happens like this: 08-28 16:15:58.233 13491-13491 E/EventBus: Could not…
Duk
  • 143
  • 12
0
votes
2 answers

EventBus is not triggered in fragments android

What Am I doing: I have a subscriber in MainActivity.Java I have registered in OnStart of activity @Override public void onCreate() { super.onCreate(); //Register the event bus for the screen …
Devrath
  • 42,072
  • 54
  • 195
  • 297
0
votes
1 answer

EventBus in viewPager fragment issue

I have thee fragments in viewpager, Fragment1, Fragment2, and Fragment3. fragment1 has a button and when onclick it setEnable(true) a button in fragment2 and the button in fragment 2 setEnable(true) a button3 in fragment3 All seem to work fine, but…
0
votes
1 answer

UI Fragment <-> EventBus <-> Service

I have an interaction between UI Fragment and background Service. I use EventBus. Of course, if Activity is stopped/killed, then there are no subscribers. Here's the code so you understand: public class LocationService extends Service { //... …
tim4dev
  • 2,846
  • 2
  • 24
  • 30
0
votes
1 answer

How to solve this when many Threads can set on/off state on progressBar

I have this AppCompatActivity that host a ViewPager containing 3 Fragments now in the AppCompatActivity toolbar I have this ProgressBar that each of the Fragment can turn on/off using the following calls: @Subscribe(threadMode =…
0
votes
1 answer

Android handle real-time output from executable through EventBus (greenbot)

To run the executable and get the real-time output I'm using the following code (with String[] command = new String[]{"/a.out"};): public static void execute(String... command) { try { ProcessBuilder builder = new…
user6450961
0
votes
1 answer

UI is not updated when OnEvent is being called in Android Event Bus

Here I used @Subscribe annotation but my calender_text is not updated.But calender_text.setText("Test") properly working in side the oncreate method.What can be the issue? @Subscribe(threadMode = ThreadMode.MAIN) public void onEvent(Date…
Rajitha Perera
  • 1,581
  • 5
  • 26
  • 42