EventBus.getDefault().unregister(this);
}
(3)接收数据时,有四个方法可以接收数据分别如下:
public void onEvent(FirstEvent event)
public void onEventAsync(FirstEvent event)
public void onEventMainThread(FirstEvent event)
public void onEventBackgroundThread(SecondEvent event)
(4)要使用一个类传递数据示例如下:
/**
- @author :huangxianfeng on 2016/11/4.
*/
public class SecondEvent {
private ArrayList mArrayList;
public SecondEvent(ArrayList mArrayList) {
this.mArrayList = mArrayList;
}
public ArrayList getmArrayList() {
return mArrayList;
}
}
(5)那么另外的Activity、Fragment中就可以传递数据,使用的方法是
EventBus.getDefault().post(new SecondEvent(mArrayList));
4.代码实例:
(1)因为上面有详细介绍,MainActivity接收消息的代码如下(接收消息的方法我们以第四个方法为例&#