RxEventBus | 中文文档
A EventBus based on RxJava2, using Retention.CLASS annotation.
- Subscriber
- register subscriber
@Override
public void onStart() {
super.onStart();
RxEventBus.getDefault().register(this);
}
- write Subscribe method, like this
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageHandle(String s) {
mTextView.setText(s);
}
- don't forget unregister when activity or others destroyed
@Override
public void onDestroy() {
super.onDestroy();
RxEventBus.getDefault().unregister(this);
}
- Post
RxEventBus.getDefault().post(mEditText.getText().toString());
Of cause you can post any kind of message, not just String
this project isn't pushed to maven, if you want to use it, just
git clone https://github.com/JoshuaRogue/RxEventBus.git
and copy module to your project.
It will be pushed to maven soon.