当前位置:网站首页>eventbus短暂使用
eventbus短暂使用
2022-07-16 16:37:00 【tea9】
2017 10 27 EventBus 是个什么鬼? 首先有两个概念发布者/订阅者
发布者就是 发送事件 订阅者 就是接收事件
gradle
compile ‘org.greenrobot:eventbus:3.0.0’
1.定义事件
public static class MessageEvent { /* Additional fields if needed */ } // 定义事件 这个就是你要传送的数据实体类
2.准备订阅者 @Subscribe(threadMode = ThreadMode.MAIN) public void onMessageEvent(MessageEvent event) {/* Do something */}; // 订阅者 接受数据的方法 threadMode 是运行在什么线程模式 http://greenrobot.org/eventbus/documentation/delivery-threads-threadmode/
注册和取消注册订阅者
@Override public void onStart() { super.onStart(); EventBus.getDefault().register(this); }
@Override public void onStop() { super.onStop(); EventBus.getDefault().unregister(this); }
3.发送事件
EventBus.getDefault().post(new MessageEvent());
边栏推荐
- Custom view
- 安利一款笔记工具---Obsidian
- Machine learning: cross entropy from theory to code
- RizomUV展UV使用记要
- Go language integer bisection template
- [Solved]splunk the captain dose not share common baseline with 1 instance
- MQ简单介绍
- 【CODETOOL】文件比较Beyond Compare使用介绍
- Equity distribution agreement (2)
- 5、 Single table query optimization
猜你喜欢

SI24R2E_智能电子学生卡2.4GHz考勤方案芯片

JMeter 21 day clock in day05

How to recover if the win11 mouse can't move? Win11 method of recovering from mouse immobility

Logs issue 2022/07/16 | Huawei Noah laboratory Zhou Min: graph data modeling and analysis from the perspective of curvature

Definition and classification standard of sensitive information

go语言整数二分模板

安卓 Day 26 :数据库Two

真正的高手,都在刻意练习(建议收藏)

「 每日一练,快乐水题 」1252. 奇数值单元格的数目
![[wechat applet] page configuration, network data request](/img/cd/2923094dcbd40c790f6743e603549d.png)
[wechat applet] page configuration, network data request
随机推荐
Okaleido: Why are we so optimistic about the multimedia NFT sector?
Logs issue 2022/07/16 | Huawei Noah laboratory Zhou Min: graph data modeling and analysis from the perspective of curvature
PHP routing (ThinkPHP 5)
【深度学习】线上租用设备平台体验以及踩过的坑(非广告)
Anaconda安装(非常详细)
行为型模式总结
Full power travel Wang Ying: Escort smart travel with data security
PHP string interception
SI24R2E_智能电子学生卡2.4GHz考勤方案芯片
阿里一面:SQL 优化有哪些技巧?
Win32-进程锁-进程异步-进程互斥-CreateMutex-OpenMutex-WaitForSingleObject-ReleaseMutex
黑马程序员-软件测试-14阶段3-功能测试-66-77禅道介绍,产品经理使用禅道,超级管理员使用禅道,超级管理员修改安全策略公司部门员工信息项目经理创建项目设置团队关联需求添加任务,产品经理需求评审,
Ci521 domestic 13.56MHz reader chip replaces cv520 compatible
个性化推荐真的是“恶魔”吗?
JMeter 21 天打卡 day05
[tools] visual studio keymap
电影知识图谱和基于模板的问答系统构建
机器学习:交叉熵从理论到代码
Company equity distribution reference
第一章 FPGA数字信号处理_数字混频(NCO与DDS)