码迷,mamicode.com
首页 > 移动开发 > 详细

Android LocalBroadcastManager提高应用安全性

时间:2015-04-01 13:28:22      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:android本地广播   localbroadcastreceiv   

  • 官方文档解释: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);

Android LocalBroadcastManager提高应用安全性

标签:android本地广播   localbroadcastreceiv   

原文地址:http://blog.csdn.net/wangduanqing5945/article/details/44804151

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!