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

Android using EventBus not updating another view after posting

I need to send a data from fragment B to A and add items to the Recyclerview inside of the Fragment A, so I'm using the EventBus to send the data and updating the list, the problem is, it only works in Debugging line by line, I mean, step by step…
Nathiel Paulino
  • 534
  • 6
  • 17
0
votes
1 answer

Build failed Android Room & EventBus

I take over an Android project and I need to modify the database (at least add entities and daos). The problem is that at the slightest change in the code, the project doesn't 'compile' anymore and I get the following…
Syxs
  • 158
  • 6
0
votes
0 answers

EventBusException: its super classes have no public methods with the @Subscribe annotation

I am working on the ROS android project. I am implementing the EventBus to constantly updating the value for textViews. I am posting values from ManActivity to MainFragment But I am getting below Error org.greenrobot.eventbus.EventBusException:…
Arpit Patel
  • 7,212
  • 5
  • 56
  • 67
0
votes
1 answer

Event Bus - Create Multiple Events

How can I create multiple events using an event bus? So in this example, I'm trying to receive multiple events. But when addEvent3WhenLogicOccers() is called values of addEvent1WhenLogicOccers() are gone because of new EventBusEvents() in the event…
user11969024
0
votes
0 answers

Why method from presenter could trigger twice since call from callback is only once (EventBus)

I got tablayout with 2 fragments. When 1st fragment go on resume we see the next flow ActivityCallMethod -> PresenterCallMethod -> RepositoryCallMethod -> repositorySendCallBackToPresenter -> EventInPresenterTriggerAndCallMethodFromView ->…
Bo Z
  • 2,359
  • 1
  • 13
  • 31
0
votes
1 answer

Cannot update recycler view from GreenRobotEventBus

From past two days, I am trying to set recycler view values received from Eventbus but getting error No adapter attached; skipping layout. I have tried and tested every code that is available on internet like 1.…
0
votes
0 answers

What is a reliable way of sending messages between process in Android?

I'm an Android newbie. I'm trying to send and receive messages between process. One thing which I'm aware of is communicating via binder calls by implementing a Service. The other message transferring mechanism which I've seen so far is Broadcast…
0
votes
1 answer

EventBus - threadMode not regonized as @Subscribe annotation property :cannot resolve method threadMode

I am using GreenRobot EventBus , I wanted to define some Threading properties, according to docs, However, when I write: @Subscribe(threadMode = ThreadMode.MAIN) public void onShowNotification(NotificationEvent event) { if(event ==…
0
votes
1 answer

Using greenrobot EventBus, if both a base class and a derived class subscribe, what happens?

I am using greenrobot EventBus. If I have a base class B, and a derived class D, and both subscribe to an event E in a function f: class E {} class B { @Subscribe public f(E e) {} } class D extends B { @Subscribe public f(E e)…
ymett
  • 2,425
  • 14
  • 22
0
votes
1 answer

How to make Eventbus run in background with BroadcastReceiver?

How to i make Greenrobot Eventbus get register or running in the background with BroadcastReceiver? I try it but its only work when the Activity or app is open when i close the app the Eventbus is stop! I use Greenrobot Eventbus to call method on…
0
votes
1 answer

How can an AppCompatActivity communicate with FragmentActivity using the EventBus?

Question, How can an AppCompatActivity communicate with FragmentActivity using the EventBus? Findings, FragmentActivity can communicate with AppCompatActivity and the onEvent method is called, but if we switch the communication path to…
0
votes
0 answers

Java android EventBus get two this same events

I create event I send this event on free activities. But When I send on only one Activity I have in @Subscribe method called multiple time for the same event
tompok
  • 27
  • 6
0
votes
1 answer

How to use EventBus?

In my application i want use EventBus and i added this dependency implementation 'org.greenrobot:eventbus:3.1.1'. I write below codes, but when run application show me force close error and close application! My Java codes: @Subscribe(threadMode =…
Hock
  • 147
  • 2
  • 2
  • 14
0
votes
1 answer

Posting data to all Android activities in Sync

I am developing an Android application which has 4 activities. Lets say ActivityA, ActivityB, ActivityC, and ActivityD. Each activity has tablayout so many fragment to display weekly data. I am downloading the data in each activity from Firebase and…
0
votes
0 answers

Dealing with Modal Dialogs when using EventBus

Let's say my App wants to fetch some data from the internet, and it does so through an AsyncTask. When this task finishes, it posts an event with the response data to the EventBus. The AsyncTask may be triggered either via a Service or an UI. If an…
Daniel F
  • 13,684
  • 11
  • 87
  • 116