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));
上一篇下一篇

猜你喜欢

热点阅读