EventBus简单使用

依赖

implementation 'org.greenrobot:eventbus:3.0.0'

EventBus 注册

public class MoEvent implements Serializable {

    public String string;

    public MoEvent(String string) {
        this.string = string;
    }
}

传值

  EventBus.getDefault().post(new MoEvent("啥东东"));

接收 粘性

    @Subscribe(threadMode = ThreadMode.MAIN,sticky = true)
    public  void onLogin(MoEvent moEvent){
        String string = moEvent.string;
    }

你可能感兴趣的:(EventBus,EventBus简单使用)