当前位置:网站首页>Differences between broadcastreceiver and localbroadcastmanager
Differences between broadcastreceiver and localbroadcastmanager
2022-06-23 23:42:00 【MirkoWug】
1. Program A Can I receive the program B Broadcast of ?
can , Use global BroadCastRecevier Can carry on the cross process communication , But notice that it can only passively receive radio . Besides ,LocalBroadCastRecevier Limited to inter broadcast communication of this process .
2. Is there a limit to the amount of data broadcast can transmit , How much is the , Why limit ?
Intent There is a size limit when passing data , Approximately limited to 1MB within , Do you use Intent To transfer data , In fact, it is cross process communication (IPC), Cross process communication requires data from the kernel copy Into the process , Each process has a buffer to receive kernel data , The default is 1M; If the data transferred at one time exceeds the limit , There will be an exception .
The performance of different manufacturers is different. It may be that the manufacturer has modified the size of this limit , It is also possible that the same object has different sizes on different machines .
Delivering big data , Should not use Intent; Consider using ContentProvider Or share memory anonymously . In simple cases, segmented transmission can be considered .
3. There are several kinds of radio registration , What are the advantages and disadvantages of each ?
The first is the resident type ( Static registration ): When the application closes, if there is a message broadcast , The program will also be called by the system , Self run .
The second is not permanent ( Dynamic registration ): The broadcast follows the life cycle of the program .
Dynamic registration
advantage : stay android In the broadcast mechanism of , Dynamic registration priority is higher than static registration priority , So if necessary , It is necessary to dynamically register broadcast recipients .
shortcoming : When used to register Activity Turn it off , And then the radio is dead .
Static registration
advantage : There is no need to worry about whether the broadcast receiver is turned off , As long as the device is on , The radio receiver is on .
4. How to intercept and abort A text message ?
Can monitor this signal , When passed to the real receiver , We will customize the broadcast receiving program to have priority over it , And cancel the broadcast , In this way, the function of intercepting short messages can be realized .
5. BroadcastReceiver,LocalBroadcastReceiver difference ?
1、 Application scenarios
1、BroadcastReceiver It is used to transfer messages between applications ;
2、 and LocalBroadcastManager Used to deliver messages within an application , Than broadcastReceiver More efficient .
2、 Security
1、BroadcastReceiver The use of Content API, So essentially it's cross application , So when you use it, you must consider not to be abused by other applications ;
2、LocalBroadcastManager There's no need to think about security , Because it only works inside the application .
3、 In principle
(1) And BroadcastReceiver In order to Binder The communication mode is different from the underlying mechanism ,LocalBroadcastManager The core implementation of is actually Handler, It's just using IntentFilter Of match function , as for BroadcastReceiver It doesn't matter if you switch to another interface , By the way, I've made use of existing classes and concepts .
(2) LocalBroadcastManager the reason being that Handler Communication within the application , Better natural safety , More efficient .
- How to make the program start automatically ?
Define a Braodcastreceiver,action by BOOT——COMPLETE, Start the program after receiving the broadcast .
边栏推荐
- 2022 information security engineer examination knowledge point: access control
- E: Unable to acquire lock /var/lib/dpkg/lock
- CTF—Go题目复现
- 1004. 最大连续1的个数 III ●●
- [design] 1359- how umi3 implements plug-in architecture
- What is an applet container
- Cause analysis and Countermeasures for FANUC robot srvo-050 collision detection alarm (available for personal test)
- Golang 类型断言
- WebService client request failed can not create a secure xmlinputfactory
- 项目中常用到的 19 条 MySQL 优化
猜你喜欢

Several guesses about the design of Tencent conference number

再来一个高仿开眼的短视频APP

“山大地纬杯”第十二届山东省ICPC大学生程序设计竞赛

iNFTnews | 创造者经济的未来在Web3世界中该去向何处?

Talking about the knowledge of digital transformation

AUTOCAD——总结CAD画圆角的三种方式

How can wechat video numbers be broadcast live on a PC?

IDEA 自动生成单元测试,效率倍增!

对不起,你的USB走线可能搞错了!

ORB_ Slam3 environment setup and demo demonstration
随机推荐
【Try to Hack】masscan
The digital transformation index report 2021 released by Tencent Research Institute has accelerated the digital transformation and upgrading of mainland enterprises!
【HackTheBox】 meow
Onsaveinstancestate callback opportunity of activity
Math. Max() method obtains the maximum value in the array and returns Nan problem analysis
[design] 1359- how umi3 implements plug-in architecture
网站如何在Google建立索引
[Xilinx ax7103 microbalze Learning Notes 6] MicroBlaze custom IP core packaging experiment
What is the production process of enterprise website? How long does it take to design and build a website?
Autofac details
嵌入式接口复习资料
Stm32-------adc (voltage detection)
kubernetes之常用核心资源对象
Bilibili × Blue bridge cloud course | online programming practice competition is new!
List中subList的add造成的死循环
STM32 ------ external interrupt
关于H5移动端用什么自动化测试
What is an applet container
iNFTnews | 创造者经济的未来在Web3世界中该去向何处?
Generate post order traversal according to pre order traversal and mid order traversal