How to use GreenRobot's EventBus in broadcasting events from Service to Activity?

╄→尐↘猪︶ㄣ 提交于 2019-12-06 07:14:44

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

EventBus.getDefault().register(this);

And unregister at onPause

EventBus.getDefault().unregister(this);

When service is running and it obtains info regarding BLE, send this info through EventBus:

BLEInfo bleInfo = new BLEInfo(... // create some kind of object to aggregate the info about ble connection
EventBus.getDefault().post(bleInfo);

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

public void onEvent(BLEInfo bleInfo) {
    // update your UI based on bleInfo
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!