当前位置:网站首页>Broadcast (broadcast)
Broadcast (broadcast)
2022-07-23 21:10:00 【shuo277】
android Four components of :
Activity、Service、BroadCast( radio broadcast )、ContentProvider
BroadCast Receiver
One of the four components , Must be in the list (androidManifest.xml) Register in the file
Is to propagate data between components (Intent) A mechanism of
APP Which one uses radio ?
Telephone
SMS
Electric quantity
WIFI Is it connected
Android The first error in ?
Time consuming operations in components , Will report application no response (ANR)
There are several kinds of broadcast receivers ?
Standard radio
Dynamic registration Use java Code registration
Static registration Directly in androidManifest.xml register
Ordered broadcasting
Realize simple static registration
1. Create broadcast recipients

2. stay AndroidManifest.xml Register broadcast recipients in
// Register dynamic broadcast recipients
MyDymnicReceiver myDymnicReceiver=new MyDymnicReceiver();
IntentFilter intentFilter=new IntentFilter();
intentFilter.addAction("HOPU2");
registerReceiver(myDymnicReceiver,intentFilter);
3. Send a broadcast
// Send broadcast to static receiver
Intent intent=new Intent();
intent.setPackage(getPackageName());
intent.setAction("HOPU");
intent.putExtra("info"," Hello Hello ");
sendBroadcast(intent);Realization
Simple dynamic registration
// Declaring container private Button button,button2; // Create internal class MyDymnicReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { Log.i(" Dynamic broadcast recipients ",intent.getStringExtra("info")); } } // Register dynamic broadcast recipients MyDymnicReceiver myDymnicReceiver=new MyDymnicReceiver(); IntentFilter intentFilter=new IntentFilter(); intentFilter.addAction("HOPU2"); registerReceiver(myDymnicReceiver,intentFilter);// Send dynamic broadcast recipients button2=findViewById(R.id.button2); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent=new Intent(); intent.setAction("HOPU2"); intent.putExtra("info","hello hello"); sendBroadcast(intent); }
边栏推荐
- A beautiful road
- 第3章业务功能开发(创建线索)
- [kernel] platform bus model for driving development and learning
- Opencv image processing Laplace pyramid
- 【微信小程序】你了解小程序开发吗?
- [wechat applet] do you know about applet development?
- 221. Largest square ● &1277. Square submatrix with statistics all 1 ● ●
- If the order is not paid within 30 minutes, it will be automatically cancelled
- 1063 Set Similarity
- First acquaintance with JS (programming suitable for beginners)
猜你喜欢

支付宝常用接口统一封装,可直接支付参数使用(适用于H5、PC、APP)

高数下|二重积分的计算2|高数叔|手写笔记

第十一天:续第十天BGP的基本配置

The third slam Technology Forum - Professor wuyihong
![[wechat applet] do you know about applet development?](/img/3d/da58255aeb6bf6bc5021d988906bcc.png)
[wechat applet] do you know about applet development?

Jetson nano recording stepping on the pit (it will definitely solve your problem)
![[continuous update] collection of raspberry pie startup and failure series](/img/f3/706a625cdc214960e2d9ca0c7ea41c.jpg)
[continuous update] collection of raspberry pie startup and failure series

第三届SLAM技术论坛-吴毅红教授

视觉slam学习|基础篇01

1309_STM32F103上增加GPIO的翻转并用FreeRTOS调度测试
随机推荐
221. 最大正方形 ●● & 1277. 统计全为 1 的正方形子矩阵 ●●
(note) learning rate setting of optimizer Adam
Himawari-8 data introduction and download method
High numbers | calculation of triple integral 2 | high numbers | handwritten notes
现在完全不知道怎么同步
The third slam Technology Forum - Professor wuyihong
Tropomi (sentinel 5p) data introduction and download method
Unity—3D数学-Vector3
[shader realizes roundwave circular ripple effect _shader effect Chapter 6]
Green Tao theorem (4): energy increment method
AB team score flow chart, get the names of the players who score three consecutive times and the names of the players who catch up with and surpass the opponents each time (PDD)
Trial record of ModelBox end cloud collaborative AI development kit (rk3568) (II)
scala编程(中级进阶实验应用)
确定括号序列中的一些位置
High numbers | calculation of double integral 2 | high numbers | handwritten notes
一时跳槽一时爽,一直跳槽一直爽?
HDU - 2586 How far away ? (multiply LCA)
Network learning infrared module, 8-way emission independent control
1061 Dating
网络学习型红外模块,8路发射独立控制