当前位置:网站首页>Eventbus is used temporarily
Eventbus is used temporarily
2022-07-18 20:17:00 【tea9】
2017 10 27 EventBus What the hell is that? ? First, there are two concept publishers / subscriber
The publisher is Send events subscriber Is to receive events
gradle
compile ‘org.greenrobot:eventbus:3.0.0’
1. Defining events
public static class MessageEvent { /* Additional fields if needed */ } // Defining events This is the data entity class you want to transfer
2. Prepare subscribers @Subscribe(threadMode = ThreadMode.MAIN) public void onMessageEvent(MessageEvent event) {/* Do something */}; // subscriber Method of receiving data threadMode Is running in what thread mode http://greenrobot.org/eventbus/documentation/delivery-threads-threadmode/
Registering and unregistering subscribers
@Override public void onStart() { super.onStart(); EventBus.getDefault().register(this); }
@Override public void onStop() { super.onStop(); EventBus.getDefault().unregister(this); }
3. Send events
EventBus.getDefault().post(new MessageEvent());
边栏推荐
- [C language] in depth understanding of conditional compilation
- Detailed explanation of volatile usage
- Codeforces Round #806 (Div. 4)(A.B.C.D.E.F)
- Small program development of private forum circle community
- 低代码三部曲之起因
- 11. Maximum value of sliding window - double ended queue of important structure
- 12. Monotonic stack - solve the problems of rainwater connection and the largest rectangle in the histogram
- 分享不停,踏浪前行 | 开发者说·DTalk 年中鉴赏
- leetcode 43. 字符串相乘 (字符串+模拟)
- leetcode 45. Jump Game II (dp)
猜你喜欢
随机推荐
OpenGL ES学习(3)——着色语言入门
Mina中的支付交易snark
Nc20566 [scoi2010] games
PSIM simulation model construction of buck circuit (II) (use of transfer function module)
Mina中的树结构
6.暴力递归转动态规划
Realize all weekly buttons of a year
4. Connect terminated threads (recycle threads)
JUC的基本使用
Récemment trouvé la Bibliothèque d'animation lottie
Horizon 8 测试环境部署(6): UAG 负载均衡配置-2
Virtualization architecture
支付流程面试思路
Detailed explanation of volatile usage
【AI应用】Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz的详情参数
Recently discovered the animation library Lottie
8.岛问题
OpenGL es learning (4) -- projection and rendering
Liu tiemeng's introduction to C language - detailed explanation of entrustment
1. Use Jekyll to build a personal blog









