EventBus框架提炼总结
来源:互联网 发布:看宝宝舌头知健康图解 编辑:程序博客网 时间:2024/06/10 01:43
1、EventBus:事件总线框架;用于组件之间的通信,实现解耦合;
2、下载地址:https://github.com/greenrobot/EventBus
3、用法:
a、注册:
EventBus.getDefault().register(this);
b、注销
EventBus.getDefault().unregister(this);
C、发布
EventBus.getDefault().post(value);
d、订阅:以onEvent开头的代表订阅事件
onEventMainThread 方法会在UI线程执行
onEventPostThread 方法会在当前发布事件的线程执行
BackgroundThread 方法如果在非UI线程发布的事件,则直接执行,和发布在同一个线程中。如果在UI线程发布的事件,则加入后台任务队列,使用线程池一个接一个调用。
Async 加入后台任务队列,使用线程池调用,异步执行。
eg.
public void onEventMainThread(String value){ if(value !=null){ tv.setText(value);//直接更新UI } }
4、原理
(1)EventBus是单例;使用EventBus.getDefault()获取;
(2)注册register时遍历当前类及其父类;将onEvent开头的、只有一个参数的Public方法遍历出来存入Map,参数为key,方法为value;
(3)发布post时根据参数遍历Map,得到方法名;
(4)使用反射执行方法;
参考资料:http://blog.csdn.net/lmj623565791/article/details/40920453
0 0
- EventBus框架提炼总结
- EventBus框架总结之用法
- EventBus框架总结之源码分析
- 秋叶语录总结提炼
- EventBus框架
- 框架eventbus
- EventBus总结
- 总结从hello word到Spring Aop框架_提炼精髓
- EventBus框架总结之支持泛型参数
- 习惯的养成—在解决问题的过程中提炼需要总结地地方(Linux 输入框架问题)
- 新框架 之 EventBus
- EventBus框架使用
- Android EventBus框架
- Android EventBus 3.0 框架
- 框架EventBus soeazy
- EventBus框架的使用
- EventBus-通信框架
- EventBus 框架详解
- MongoDB 3.0 for java 学习记录(一、java连接MongoDB)
- vertica安装记录
- redis 安装 配置 启动
- html标签
- 通过TortoiseSVN 上传 so 文件到svn
- EventBus框架提炼总结
- View之Spinner
- 为什么要使用u-boot
- 【Java】----宏观感性认识
- Tachyon的安装、配置和使用
- 此证书的签发者无效
- QWidget rect和geometry的区别
- 设计模式-代理
- 用grunt搭建自动化的web前端开发环境-完整教程