依赖
//EventBus
implementation ‘org.greenrobot:eventbus:3.1.1’
接收消息页面
注册EventBus
EventBus.getDefault().register(this);
发消息页面
//发消息
EventBus.getDefault().post(new Msg(“我使用EventBus3.0发送消息”));
接收消息:
@Subscribe(threadMode = ThreadMode.MAIN)
public void getMsg(Msg msg){
String msg1 = msg.getMsg();
Toast.makeText(this, "接收消息:"+msg1, Toast.LENGTH_SHORT).show();
}