EventBus
来源:互联网 发布:模拟电脑桌面的软件 编辑:程序博客网 时间:2024/06/07 01:13
一. 概述
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);
阅读全文
0 0
- EventBus
- EventBus
- EventBus
- EventBus
- EventBus
- EventBus
- EventBus
- EventBus
- EventBus
- EventBus
- EventBus
- EventBus
- EventBus
- Eventbus
- EventBus
- EventBus
- EventBus
- EventBus
- Spring Data Redis(Redis Cluster)
- 关于urllib2.urlopen()的理解
- IOS挖坑之路1
- android adb 命令
- android调试so文件记录(一)
- EventBus
- Spring Data Redis(Redis Repositories)
- 欢迎使用CSDN-markdown编辑器
- Linux正则表达式grep
- 实现一个简单的服务自启动shell脚本
- 新浪web前端面试经验
- 戴尔poweredge r730服务器配置及系统安装详解教程
- 如何修改Apache默认端口
- .NET Framework 4.5 中chart(图表)控件的使用