EventBus是一个Android端优化的publish/subscribe消息总线,简化了应用程序内各组件间、组件与后台线程间的通信。比如请求网络,等网络返回时通过Handler或Broadcast通知UI,两个Fragment之间需要通过Listener通信,这些需求都可以通过EventBus实现。
使用流程:
1.定义事件类型:
public class MyEvent {}
2.定义事件处理方法:
public void onEventMainThread
3.注册订阅者:
EventBus.getDefault().register(this)
4. 发送事件:
EventBus.getDefault().post(new MyEvent())