当前位置:网站首页>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 "));边栏推荐
- Usegeneratedkeys=true configuration
- MFS详解(六)——MFS Chunk Server服务器安装与配置
- [JS] handwriting call(), apply(), bind()
- Explication détaillée du triangle Yang hui
- The title of the WebView page will be displayed in the top navigation bar of the app. How to customize
- 华为开发者认证与DevEco Studio编译器下载
- Intelligent digital asset management helps enterprises win the post epidemic Era
- 杨辉三角形详解
- Applet export (use) public function, public data
- Wechat applet uploads pictures (preview deletion limits the size and number of pictures)
猜你喜欢

php 分布式事务 原理详解
![[solution] camunda deployment process should point to a running platform rest API](/img/ef/5b893e9c315c10db6c1db46b4c3f5a.jpg)
[solution] camunda deployment process should point to a running platform rest API

MFS详解(七)——MFS客户端与web监控安装配置

智能数字资产管理助力企业决胜后疫情时代
Not in the following list of legal domain names, wechat applet solution

Solutions to common problems in small program development

Rk3399 hid gadget configuration
![A glimpse of [wechat applet]](/img/ef/17564759e720b06c2bd496d1db7544.jpg)
A glimpse of [wechat applet]

The Boys x PUBGMOBILE 联动火热来袭!来看最新游戏海报
![[DP 01 backpack]](/img/be/1e5295684ead652eebfb72ab0be47a.jpg)
[DP 01 backpack]
随机推荐
智能数字资产管理助力企业决胜后疫情时代
无刷直流电机矢量控制(四):基于滑模观测器的无传感器控制
Rk3399 hid gadget configuration
【新手上路常见问答】一步一步理解程序设计
Introduction to USB learning (5) -- looking back, the man was in the dim light
App performance test: (I) startup time
Wechat applet development (requesting background data and encapsulating request function)
Wechat applet: use of global state variables
电镀挂具RFID工序管理解决方案
[DP 01 backpack]
Binary search
You should consider upgrading via
Echart折线图:当多条折线图的name一样时也显示不同的颜色
Wechat applet (function transfer parameters, transfer multiple parameters, page Jump)
推荐扩容工具,彻底解决C盘及其它磁盘空间不够的难题
Uniapp dynamically shows / hides the navigation bar return button
JVM Foundation
Printf function
Applet disable native top
ADB shell CMD overlay debugging command facilitates viewing system framework character resource values