Eventbus在fragment初始化

``

//注册
@Override
public void onStart() {
    super.onStart();
    if (!EventBus.getDefault().isRegistered(this)) {
        EventBus.getDefault().register(this);
    }

}


解绑
@Override
public void onDestroyView() {
    super.onDestroyView();
    EventBus.getDefault().unregister(this);
}
接收
   @Subscribe(threadMode = ThreadMode.MAIN)
    public void BusOrderEvent(BusOrderEvent event) {
        LoggerUtils.e(TAG, "event " + event.getMsg());
 
       
    }
//发送消息
 EventBus.getDefault().post(new BusOrderEvent("" + recordList.get(position)));
public class BusOrderEvent {

    private String msg;

    public BusOrderEvent(String msg) {
        this.msg = msg;
    }

    public String getMsg() {
        return msg;
    }

你可能感兴趣的:(Eventbus在fragment初始化)