eventbus
2017-09-15 本文已影响7人
小白猿
注册eventbus
有注册就要有取消注册,在页面onDestroy()
方法中调用
- 注册
private void registerRefreshData() {
unRegisterRefreshData();
mRefreshDisposable = RxBus.getInstance()
.toFlowable(EventBus.class)
.subscribe(bus -> {
if (EventBus.MESSAGE.S_CHANGE_BOOK.equals(bus.getMessage()) ||
EventBus.MESSAGE.S_LOGIN_SUCCESS.equals(bus.getMessage()) ||
EventBus.MESSAGE.S_LOGOUT_SUCCESS.equals(bus.getMessage())) {
mvpPresenter.getDatas();
} else if (EventBus.MESSAGE.S_CHANGE_BOOK_ADD.equals(bus.getMessage()) ||
EventBus.MESSAGE.S_CHANGE_BOOK_DEL.equals(bus.getMessage()) ||
EventBus.MESSAGE.S_CHANGE_BOOK_UPD.equals(bus.getMessage())) {
mvpPresenter.getDatasFromDataBase();
}
});
}
- 取消注册
private void unRegisterRefreshData() {
if (mRefreshDisposable != null) {
mRefreshDisposable.dispose();
}
}
- 发出事件,传递数据
RxBus.getInstance().post(
new EventBus(EventBus.MESSAGE.S_ALBUM_SECTION_CHANGE));