使用LocalBroadcastManager
来源:互联网 发布:淘宝为你推荐怎么取消 编辑:程序博客网 时间:2024/05/07 01:27
LocalBroadcastManager是Android Support包提供了一个工具,是用来在同一个应用内的不同组件间发送Broadcast的。
使用LocalBroadcastManager有如下好处:
- 发送的广播只会在自己App内传播,不会泄露给其他App,确保隐私数据不会泄露
- 其他App也无法向你的App发送该广播,不用担心其他App会来搞破坏
- 比系统全局广播更加高效
和系统广播使用方式类似:
先通过LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
获取实例
然后通过函数 registerReceiver来注册监听器
- lbm.registerReceiver(new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- // TODO Handle the received local broadcast
- }
- }, new IntentFilter(LOCAL_ACTION));
- Read more: http://blog.chengyunfeng.com/?p=498#ixzz2l9b1fFR2
通过 sendBroadcast 函数来发送广播
0 0
- 使用LocalBroadcastManager
- 使用LocalBroadcastManager
- 使用LocalBroadcastManager
- 使用LocalBroadcastManager
- 使用LocalBroadcastManager
- 使用LocalBroadcastManager
- 使用LocalBroadcastManager
- 使用LocalBroadcastManager
- LocalBroadcastManager 使用详结
- LocalBroadcastManager的使用
- LocalBroadcastManager使用简析
- LocalBroadcastManager 使用小结
- LocalBroadcastManager的使用总结
- LocalBroadcastManager 的使用
- android LocalBroadcastManager的使用
- LocalBroadcastManager的使用
- Android LocalBroadCastManager 使用总结
- LocalBroadcastManager
- 各种报错啊 = =;
- Curator之Recipes之选举
- leetcode - Contains Duplicate II -- 重点
- Android Studio系列教程一--下载和安装
- larvavel 使用config下的配置文件
- 使用LocalBroadcastManager
- (坑点背包)0-1哈理工OJ1558
- newline in constant error
- 为CRM系统中常见数据类型进行赋值(statecode)
- CocoaPods安装和使用教程
- 访问内容提供者(和上文联系),测试
- 生成验证码java,利用structs2框架
- SCU 2401 *** The Story Of Finding Love
- 安卓--彻底让你彻明白什么是回调?