0

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 Activity from BroadcastReceiver.

Any suggest or better way to use other code?

Naxsami
  • 123
  • 4
  • 16
  • You can check answers in both these questions [here](https://stackoverflow.com/questions/33141091/is-it-good-to-replace-broadcast-receiver-with-greenrobot-eventbus-for-triggering) and [here](https://stackoverflow.com/questions/43250510/how-to-receive-eventbus-events-when-activity-is-in-the-background) – Amin Mar 12 '19 at 06:55

1 Answers1

1

Try to implement it like this,

In your Activity's onResume method, register for events:

EventBus.getDefault().register(this);

And unregister at onPause

EventBus.getDefault().unregister(this);

Finally, implement the activity's behavior for getting the info:

@Subscribe public void onEvent(Intent intent) { // do something }

Make sure that your Subscribe method is public otherwise it will not be called.

Please tell me If you have any query.

Seeya
  • 91
  • 2