当前位置:网站首页>Simple use of event bus
Simple use of event bus
2022-06-13 06:21:00 【Novice Xiaowang】
1. Import dependence
implementation 'org.greenrobot:eventbus:3.0.0'2. Customize Event class
public class MyEvent {
String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public MyEvent(String message) {
this.message = message;
}
}3. Registering and unsubscribing
// Registration events
EventBus.getDefault().register(MainActivity.this);
// Unregister event
EventBus.getDefault().unregister(MainActivity.this);4. Define how to handle events
@Subscribe(threadMode = ThreadMode.MAIN)
public void handleEvent(MyEvent myEvent){
textView.setText(myEvent.getMessage());
}5. Send events
EventBus.getDefault().post(new MyEvent(" Send custom events "));边栏推荐
- Dynamic link library nesting example
- High burst solution 2
- RN Metro packaging process and sentry code monitoring
- Huawei developer certification and deveco studio compiler Download
- 推荐扩容工具,彻底解决C盘及其它磁盘空间不够的难题
- How to view APK version number from apk
- php 分布式事务 原理详解
- 智能数字资产管理助力企业决胜后疫情时代
- JS to realize bidirectional data binding
- Status management --provider
猜你喜欢

Recommend a capacity expansion tool to completely solve the problem of insufficient disk space in Disk C and other disks

Echart histogram: echart implements stacked histogram
![[2022 college entrance examination season] what I want to say as a passer-by](/img/d7/3813b944dc2df182455d475a3669fb.jpg)
[2022 college entrance examination season] what I want to say as a passer-by

Learning records countless questions (JS)

【DP之01背包】

杨辉三角形详解
![[DP 01 backpack]](/img/be/1e5295684ead652eebfb72ab0be47a.jpg)
[DP 01 backpack]

华为开发者认证与DevEco Studio编译器下载

Echart折线图:当多条折线图的name一样时也显示不同的颜色

1+1 > 2, share creators can help you achieve
随机推荐
Download and installation of universal player potplayer, live stream m3u8 import
PHP redis makes high burst spike
php redis 制作高迸发秒杀
Super model logo online design and production tool
Echart柱状图:echart实现堆叠柱状图
Using the shutter floor database framework
Wechat applet: basic review
Adding classes dynamically in uni app
pthon 执行 pip 指令报错 You should consider upgrading via ...
View绘制整体流程简析
MFS详解(七)——MFS客户端与web监控安装配置
微信小程序:点击事件获取当前设备信息(基础)
DLL bit by bit
Using async await in applets
Custom view - extensible collapsexpendview
Echart矩形树图:简单实现矩形树图
The title of the WebView page will be displayed in the top navigation bar of the app. How to customize
Uniapp mobile terminal uses canvas to draw background convex arc
Uniapp (upload local pictures, preview pictures, convert Base64 format, upload audio files)
Echart line chart: different colors are displayed when the names of multiple line charts are the same