##一. 概述
EventBus主要是用来代替Intent,BrodCast在Fragment,Activity,Serice,
线程之间传递消息,优点是: 开销小,代码更优雅,以及将发送者和接收者解耦。
1、下载EventBus的类库
源码:https://github.com/greenrobot/EventBus
2、基本使用
(1)自定义一个类,可以是空类,比如:
public class AnyEventType {
public AnyEventType(){}
}
(2)在接收界面进行注册
eventBus.register(this);
(3)发送消息
eventBus.post(new AnyEventType event)
(4)接受消息的页面实现(共有四个函数,各功能不同,这是其中之一,可以选择性的实现,这里先实现一个):
public void onEvent(AnyEventType event) {}
(5)解除注册
eventBus.unregister(this);