Android LocalBroadcastManager提高应用安全性
-
官方文档解释:Helper to register for and send broadcasts of Intents to local objects within your process. This is has a number of advantages over sending global broadcasts with
Context.sendBroadcast(android.content.Intent)
:- You know that the data you are broadcasting won‘t leave your app, so don‘t need to worry about leaking private data.
- It is not possible for other applications to send these broadcasts to your app, so you don‘t need to worry about having security holes they can exploit.
- It is more efficient than sending a global broadcast through the system.
意义是:翻译下,1、你正在发送的数据不会超出你的应用,所以不用担心泄露应用私有数据。 -
2、其他应用发送的广播不会发送到你的APP,所以你不用担心有安全性的攻击。
-
3、本地广播比全局广播更高效
创建
final LocalBroadcastManager localBroadcastManager=LocalBroadcastManager.getInstance(this);
注册:
IntentFilter filter=new IntentFilter(); filter.addAction("duanqing.test.localbroadcast.fly"); localBroadcastManager.registerReceiver(new MyBroadCastReceiver(),filter);
发送代码:
Intent intent=new Intent(); intent.setAction("duanqing.test.localbroadcast.fly"); localBroadcastManager.sendBroadcast(intent);
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。