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

Greenrobot eventBus for Android - how to create a non-default event bus

i am making a mvp app and i want it to have the following architecture (more or less) in terms of event bus @greenrobot: The problem is i am using greenrobot as the event bus and i desire to have TWO event buses. one for the data bus and one for…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
0
votes
2 answers

RealmResults not being destroyed on new eventbus post

I'm trying to use GreenRobot to share RealmResults between fragments. When the user clicks certain buttons changing the data I want to show, I call invalidateRealmResult: public void invalidateRealmResult() { RealmQuery realmQuery = …
chanban
  • 480
  • 1
  • 4
  • 19
0
votes
1 answer

Android Greendao to auto increment always be long

Android Greendao to auto increment always be long thats why its can't increment value automatically Please help us to how we can create schema to automatically get as Long My code is here Entity label = schema.addEntity("SecureNotes"); …
mbpatel
  • 501
  • 1
  • 5
  • 19
0
votes
1 answer

My subscribe method is called even before my greenrobot bus posts an event

I'm trying to post an event from within a subscriber @Subscribe public void onFirstEvent(FirstEvent event) { ... bus.post(new SecondEvent(...)); } And in my other class, where I handle SecondEvent, I use a subscribe method in the same way.…
stack
  • 225
  • 4
  • 12
0
votes
2 answers

Posting Objects through Event Bus Post

How many events should i post for a single Event Bus? For Example - Registering Event Bus - EventBus.getDefault().register(this); Posting Event - EventBus.getDefault().post(Object); And is there any problem causes if i could not unregister the…
sanil
  • 482
  • 1
  • 7
  • 23
0
votes
0 answers

Android app long-click: works in from Android Studio, not otherwise

This is a really bizarre one.... I've written a very simple Android shopping-list app which uses a RecyclerView. I want the user to long-click on an item to select it for deletion, etc. The long-click works fine when I run the app from Android…
Ray O'Donnell
  • 759
  • 4
  • 11
0
votes
0 answers

get Switch-Button State in Fragment from Activity with Eventbus

I´ve got the following scenario: I have a MainActivity which hosts 3 Fragments (Tabs). In my Fragment I´ve got two Switch-Toggles, whose state I would like to publish to the hosting Activity (MainActivity) with EventBus. I´ve set up two…
0
votes
1 answer

Background thread vs Async thread pool

I see from the GreenRobot EventBus documentation that with thread mode BACKGROUND a single background thread is used and with thread mode ASYNC a thread pool is used. Anyone happen to know whether the background thread used by the BACKGROUND thread…
Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
0
votes
1 answer

When is onEvent called in a fragment and is there a way of determining when it can be called?

I was under the impression that onEvent can be triggered as soon as the fragment starts if it is placed in the onStart() and onResume method . Please have a look at my fragment below . That method prepareListData is ment to sort the list before I…
Zidane
  • 1,696
  • 3
  • 21
  • 35
0
votes
1 answer

OnEvent cast incorrect event Object using EventBus

I have register EventBus on both Activity (BaseActivity) and Fragment (BaseFragment). So, I catch event with: In BaseActivity, and BaseFragment I have same code: public void onEvent(Object object) { // do nothing } In my child fragment (A)…
NamNH
  • 1,752
  • 1
  • 15
  • 37
0
votes
1 answer

Android EventBus app crashes in release mode due to no @Subcribe methods

The app works in debug, but not in release Process: com.rubenwardy.monzolytics, PID: 14943 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rubenwardy.monzolytics/com.rubenwardy.monzolytics.MainActivity}:…
rubenwardy
  • 679
  • 5
  • 21
0
votes
3 answers

How to setup EventBus into fragment

I am experimenting EventBus libaray. I just registered it into Fragment and I used @Subcride annotation into that fragment with public methods but when I run the app I get exception which tells that I don't have used @Subcribe annotation with public…
0
votes
2 answers

Android - Greenrobot EventBus in android?

I am using from greenrobot:eventbus in my project: compile 'org.greenrobot:eventbus:3.0.0' Problem : I am using from EventBus for GPS like bellow : public class ConditionGPS { public static void statusCheck(Activity activity) { final…
0
votes
1 answer

How to send events in android where we can choose the subscribers?

I have 4 classes all subscribed to event Message. I want to send event Message only to 2 of the classes. EventBus is sending event to all the 4 classes.
Nikhil
  • 104
  • 8
0
votes
1 answer

Different between EventBus vs Handler in android

I used android Handler for step by step processes in my apps. For example, after setp_1 finished, send message to handler and then start step_2. Now I found greenrobot EventBus. I interested in it performance and features. I want to replace android…
user1156041
  • 2,155
  • 5
  • 24
  • 54