EventBus的使用初试
2013-11-08 16:26
176 查看
当一个Android应用功能越来越多的时候,保证应用的各个部分之间高效的通信将变得越来越困难。如何优雅地解决这个问题?这时候,就需要使用到EventBus。
![](http://cms.csdnimg.cn/article/201305/21/519b0d442e3e7_middle.jpg)
EventBus是GreenRobot出品的Android系统的一个Event Bus类库,使用起来和之前我们所介绍的Square的Otto差不多,都是用来简化应用组件之间的通信。
1、下载EventBus的类库
https://github.com/greenrobot/EventBus
2、基本使用
Implement any number of event handling methods in the subscriber:接受发送的消息
Register subscribers:注册
Post events to the bus:发送消息
Unregister subscriber:解除注册
1、在你要接受消息的组件中,例如Activity中,注册EventBus
2、在其他的组件中,你需要通知注册了的Activity时,只需要EventBus.getDefault().post(new PhotoSelectionRemovedEvent());上面的Activity中onEvent方法中就可以接受到消息了,去处理一些事情
![](http://cms.csdnimg.cn/article/201305/21/519b0d442e3e7_middle.jpg)
EventBus是GreenRobot出品的Android系统的一个Event Bus类库,使用起来和之前我们所介绍的Square的Otto差不多,都是用来简化应用组件之间的通信。
1、下载EventBus的类库
https://github.com/greenrobot/EventBus
2、基本使用
Implement any number of event handling methods in the subscriber:接受发送的消息
public void onEvent(AnyEventType event) {}
Register subscribers:注册
eventBus.register(this);
Post events to the bus:发送消息
eventBus.post(event);
Unregister subscriber:解除注册
eventBus.unregister(this);
1、在你要接受消息的组件中,例如Activity中,注册EventBus
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); EventBus.getDefault().register(this); } @Override protected void onDestroy() { super.onDestroy(); EventBus.getDefault().unregister(this); } public void onEvent(PhotoSelectionRemovedEvent event) { // refreshSelectedPhotosTitle(); // refreshUploadActionBarView(); Log.i("LogUtil", "LogUtil....onEvent"); }
2、在其他的组件中,你需要通知注册了的Activity时,只需要EventBus.getDefault().post(new PhotoSelectionRemovedEvent());上面的Activity中onEvent方法中就可以接受到消息了,去处理一些事情
相关文章推荐
- EventBus 使用介绍
- EventBus使用
- EventBus的使用
- EventBus轻松使用
- Android中Eventbus的使用
- 515_EventBus使用
- EventBus 3使用文档(一)
- EventBus 的使用方法
- EventBus使用详解(二)
- EventBus的使用
- iOS 项目中使用CocoaPod管理项目初试
- 【开源框架】EventBus 消息总线使用
- Android--EventBus的使用介绍
- EventBus使用详解(一)——初步使用EventBus
- Android:EventBus-3 基本使用
- EventBus使用详解(一)——初步使用EventBus
- EventBus使用详解(二)——EventBus使用进阶
- Android EventBus 3.0.0 使用总结
- EventBus 使用介绍
- EventBus 3.0 的使用