Android 使用EventBus发送消息接收消息

基本使用

自定义一个类

public class LoginEvent {
private String code;//是否成功

public LoginEvent(String code) {
this.code = code;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}
}

在要接收消息的页面注册:

   eventBus.register(this);  

public void onEventMainThread(LoginEvent event) {

}

 

解除注册

eventBus.unregister(this);  



引入EventBus:
compile 'org.greenrobot:eventbus:3.0.0'



原文地址:https://www.cnblogs.com/zhaoleigege/p/5957360.html