当前位置:网站首页>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); }
边栏推荐
- Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]
- [Yunxiang book club No. 13] Chapter IV packaging format and coding format of audio files
- TCP half connection queue and full connection queue (the most complete in History)
- STM32c8t6驱动激光雷达(一)
- The common interfaces of Alipay are uniformly encapsulated and can be used directly for payment parameters (applicable to H5, PC, APP)
- High numbers | calculation of double integral 2 | high numbers | handwritten notes
- Identify some positions in the parenthesis sequence
- Stm32c8t6 driving lidar actual combat (II)
- 对接湖南CA使用U_KEY登录
- [wechat applet] do you know about applet development?
猜你喜欢

Visual slam learning | basic chapter 01

How to get the worker's hat? Where is the worker's helmet?

Junior intern, ByteDance, after sharing, has been offered

【微信小程序】你了解小程序开发吗?

Stm32c8t6 driving lidar actual combat (II)

Himawari-8 data introduction and download method

Unity—3D数学-Vector3

221. 最大正方形 ●● & 1277. 统计全为 1 的正方形子矩阵 ●●

LeetCode热题 HOT52-100

Modular development
随机推荐
[100 cases of scratch drawing] Figure 46-scratch drawing flowers children's programming scratch programming drawing case tutorial grade examination competition drawing training case
Minimum spanning tree: Kruskal
Green Tao theorem (4): energy increment method
The common interfaces of Alipay are uniformly encapsulated and can be used directly for payment parameters (applicable to H5, PC, APP)
A beautiful road
[Yunxiang book club No. 13] Chapter IV packaging format and coding format of audio files
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)
When we talk about Chen Chunhua and Huawei, what are we talking about?
05_ue4进阶_材质UV缩放
Preprocessing tropomi (sentinel 5p) data with envi
大三实习生,字节跳动面经分享,已拿Offer
Major upgrade of openim - group chat reading diffusion model release group management function upgrade
Vite3 learning records
High numbers | calculation of double integral 3 | high numbers | handwritten notes
Pay more attention to which securities company has the lowest commission? Is it safe to open an account online?
Major optimization of openim - Message loading on demand, consistent cache, uniapp Publishing
Day 12: continued day 11 (BGP related knowledge)
Green Tao theorem (3): anti uniform functions and their generated sigma Algebras
Stm32c8t6 driven lidar (I)
做一个有职业操守的软件匠人