Reputation: 133
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?
Upvotes: 0
Views: 441
Reputation: 91
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.
Upvotes: 1