Android ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to register to receive intents
ReceiverCallNotAllowedException
mContext.registerReceiver()不能在BroadcastReceiver的onReceive()里面调用
可以通过context.getApplicationContext().registerReceiver()来解决
提高context的级别
另外在网上搜索的时候,发现
BroadcastReceiver的onReceive()里面调用bindService()方法也会出现这个Exception
Note: this method can not be called from a BroadcastReceiver component.
A pattern you can use to communicate from a BroadcastReceiver to a Service is to call startService(Intent) with the arguments containing the command to be sent, with the service calling its stopSelf(int) method when done executing that command.
See the API demo App/Service/Service Start Arguments Controller for an illustration of this.
It is okay, however, to use this method from a BroadcastReceiver that has been registered with registerReceiver(BroadcastReceiver, IntentFilter), since the lifetime of this BroadcastReceiver is tied to another object (the one that registered it).
bindService不能在BroadcastReceiver 中调用,你可以在里面调用StartService并把要传递参数放到intent中
Android ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to register to receive intents的更多相关文章
- Android API之android.content.BroadcastReceiver
android.content.BroadcastReceiver Base class for code that will receive intents sent by sendBroadcas ...
- Android中BroadcastReceiver的两种注册方式(静态和动态)详解
今天我们一起来探讨下安卓中BroadcastReceiver组件以及详细分析下它的两种注册方式. BroadcastReceiver也就是"广播接收者"的意思,顾名思义,它就是用来 ...
- Android 广播 BroadcastReceiver
Android 系统里定义了各种各样的广播,如电池的使用状态,电话的接收和短信的接收,开机启动都会产生一个广播.当然用户也可以自定义自己的广播. 既然说到广播,那么必定有一个广播发送者,以及广播接收器 ...
- Android中BroadcastReceiver广播
BroadCastReceiver 简介 广播接收者( BroadcastReceiver )用于接收广播 Intent ,广播 Intent 的发送是通过调用 Context.sendBroadca ...
- java攻城狮之路(Android篇)--BroadcastReceiver&Service
四大组件:activity 显示. contentProvider 对外暴露自己的数据给其他的应用程序.BroadcastReceiver 广播接收者,必须指定要接收的广播类型.必须明确的指定acti ...
- Android广播BroadcastReceiver 二
BroadcastReceiver: 在Android中,Broadcast是一种广泛运用的在应用程序之间传输信息的机制.而BroadcastReceiver是对发送出来的 Broadcast进行过滤 ...
- Android广播BroadcastReceiver 一
Android 系统里定义了各种各样的广播,如电池的使用状态,电话的接收和短信的接收,开机启动都会产生一个广播.当然用户也可以自定义自己的广播. 既然说到广播,那么必定有一个广播发送者,以及广播接收器 ...
- Android之BroadcastReceiver 监听系统广播
绑定广播有两种方式 一.配置文件绑定,在程序未启动也能监听 二.代码方式绑定,在程序启动后才能监听 1.绑定和取消绑定广播 public class MainActivity extends Acti ...
- android中broadcastreceiver的用法-代码中注册
界面如下: 问题1:点击“解绑广播接收器“后再次点击”解绑广播接收器“后,程序崩溃,log信息如下: 08-04 05:04:35.420: E/AndroidRuntime(5521): F ...
随机推荐
- 关于js闭包是否真的会造成内存泄漏(转载)
闭包是一个非常强大的特性,但人们对其也有诸多无解.一种危言耸听的说法是闭包会造成内存泄露. 局部变量本来应该在函数退出的时候被解除引用,但如果局部变量被封闭在闭包形成的环境中,那么这个局部变量就能一直 ...
- android studio使用的各种问题
1.添加权限,没有图形界面.添加权限的位置在<application>节点外,如果在节点内添加会报错的 2.查看logcat:要查看logcat的内容,要点一下设备 3.显示行号:在set ...
- 用户登录session_id观看
通过使用浏览器firefox或者google看cookie id, 这样就知道登录状态怎么样了
- 利用UICollectionView实现瀑布流
利用UICollectionView实现瀑布流通过自定义布局来实现. - 自定义类继承UICollectionViewLayout: 必须重写的方法有: //决定每个item的位置: - (nulla ...
- 1 初级.net web工程师,在工作中都做些什么
初级.Net Web工程师,在工作中都做些神马? 职责 初级.Net Web工程师的主要职责,就是按比较详细的要求去完成代码. 比较详细的要求是指:一般会把页面式样.功能的描述.数据库结构.性能要 ...
- 转:JS线程和JS阻塞页面加载的问题
前几日写了一篇文章,介绍了js阻塞页面加载的问题.当时是通过例子来验证的.今天,我介绍一下浏览器内核,从原理上介绍一下js阻塞页面加载的原因. 浏览器的内核是多线程的,它们在内核制控下相互配合以保持同 ...
- Qt编程中,Ui文件如何被利用
这两天跟着班级辅导,总有学生感到很疑惑,用ui designer设计出来的ui文件是如何使用的,下面我从一个例子来说明下,希望能对有这样疑惑的同学有帮助. 事实上,现在有了继承设计工具qtcreato ...
- CMake 简单介绍
CMake特点 CMake需要用户用CMake规范的语法编写CMake脚本,该语法简单易用,入门极其顺手 原生支持 C/C++/Fortran/Java 的相依性的自动分析功能,免除了程序员对代码依赖 ...
- Android平台一些流行的使用3D技术开发的锁屏
题外话:从2007年android系统的发布开始,到2008年的第一款手机问世,再到现在击败塞班,wm,黑霉,然后遍地开花,2013年,智能机出货超过了功能机,android功不可没.一路走来,虽然a ...
- javascript实现贪吃蛇
<html> <head> <style> body { background:#444; } .rect { border:1px solid #94F; wid ...