1. 注册
新建MyApplication extends Application,在onCreate()里写 EventBusBuilder builder = EventBus.builder();
builder.installDefaultEventBus();
2. 接收方在onCreate() 里写:
Eventbus.getDefault.register(this);
onDestroy()里写:
Eventbus.getDefault.unregister(this);
@Subscribe(threadMode = ThreadMode.MAIN) // 对UI进行更改,所以写在主线程中
public void xxx (我们定义的类){
实现
}
3. 发送方
Eventbus.getDefault.post(自己定义的类);