Android LocalBroadcastManager提高應用安全性

來源:互聯網
上載者:User

標籤: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 withContext.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提高應用安全性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.