has leaked IntentReceiver ...that was originally registerd here.Are you missing a call to unregister
今天碰到了这个错误:has leaked IntentReceiver ...that was originally registerd here.Are you missing a call to unregisterReceiver
如图所示:
这个错误的中文意思是,已经溢出了IntentReceiver,你是忘记了调用注销广播的方法吗?
原因所在:
之所以是溢出IntentReceiver,原因是有receiver 被register后没有被unregister,反复几次后造成 intentReceiver 泄漏
但我其实是有调用unregisterReceiver(batteryReceiver),那为什么还会出现这个问题
解决方法:
为了避免这个问题的出现,注册广播和注销广播要成对出现,但同时又为了避免空指针的问题,我们最好加一个标志位flag
/*** 标志位,是否broadcaseReceiver开启,默认为false*/boolean flag=false;
在注册广播的时候,将flag变为true
/*** 注册广播*/private void registerReceiver() {flag=true;IntentFilter filter = new IntentFilter();filter.addAction(Intent.ACTION_BATTERY_CHANGED);batteryReceiver=new BatteryReceiver();registerReceiver(batteryReceiver, filter);}
在注销广播的之前,先判断flag是否为真,(即是否广播已经被注册了),如果为真,则注销广播
@Overridepublic void onPause() {if(flag){flag=false;unregisterReceiver(batteryReceiver);}super.onPause();}
之所以加flag,就是避免没有注册广播,但却注销广播,这样会有空指针
转载请注明出处,谢谢http://blog.csdn.net/harryweasley/article/details/45092041
has leaked IntentReceiver ...that was originally registerd here.Are you missing a call to unregister相关推荐
- Activity has leaked window that was originally added 问题解决
在做练习的时候,切换屏幕竖恒状态时,会出现Activity has leaked window that was originally added 错误.网上查询得知原因是因为alertDilaog没 ...
- Dialog使用时has leaked window...that was originally added here错误
错误提示 android.view.WindowLeaked: Activity - has leaked window - that was originally added here 分析: 经常 ...
- Activity has leaked window that was originally added解决办法
在使用ProgressDialog的时候,有可能会遇到"Activity has leaked window that was originally added"的错误,原因 ...
- Android bindService报错:has leaked ServiceConnection ***that was originally bound here
在android的activity中bindService,出现了"has leaked ServiceConnection ***that was originally bound her ...
- Activity has leaked window that was originally added
错误: E/WindowManager: android.view.WindowLeaked: Activity com.x.x.x has leaked window com.android.int ...
- android 异常leaked intentreceiver
该异常指:有receiver 被register后没有被unregister,反复几次后造成 intentReceiver 泄漏 解决方法:onPause中unregisterReceiver
- android:报Activity has leaked IntentReceiver或者re...
2019独角兽企业重金招聘Python工程师标准>>> 原因: 很可能是直接调用registerReceiver(......)和unregisterReceiver(......) ...
- android:报Activity has leaked IntentReceiver或者receiver is not registered错误
原因: 很可能是直接调用registerReceiver(......)和unregisterReceiver(......),导致这两个方法找不到. 解决办法: 在registerReceiver( ...
- Android S动态广播注册流程(广播1)
Android S动态广播注册流程 1. 动态广播注册的流程 2. 新建一个动态广播接收者 3. App部分的registerReceiver 4. system_server侧的广播注册 5. 总结 ...
最新文章
- 用了 Elasticsearch 后,查询起飞了!
- python下载大文件-python 大文件
- 分享--关于学习的一些事儿
- 从postgress 读取数据
- 花果山第一届猿类分级考试实录--Talk is cheap,Show me the code
- 【SSL】Tomcat8.5 SSL/HTTPS 安装证书 单向认证
- 隔一段时间查找一次 golang_剑指 offer-04 二维数组中的查找
- ADO.NET 完整修改、删除、防字符串攻击
- 使用 docker+tmux 加强容器调度
- 冒泡排序,递归二分查找法,二分法
- 【暖*墟】#树链剖分# 树链剖分学习与练习
- 诺基亚100G光传输网络助力Jio泛印度4G网络大幅增长
- xci转nsp工具_【ns新系统11.0.0发布】安装工具已经更新至4.2【后面附上批处理内容修改】...
- PHP合并多个excel文件
- 2019年区块链专利增速可能放缓?
- mysqli被遗弃了_在您的申请中被遗忘的权利
- 用户画像 各维度表的结构图
- Deep Lab 系列总结
- MIT6.828_HW9_barriers
- 2021年R2移动式压力容器充装考试技巧及R2移动式压力容器充装模拟考试题
热门文章
- JavaScript 中的“黑话”,你知多少?
- python好学吗要有什么基础-Python0基础好学吗?
- mysql查询练习tblstudent_通过Navicat进行MySQL的基础查询练习
- golang后台管理系统Iris+Layui框架搭建教程
- ARC下循环引用的问题
- 计算机中操作系统的主要功能是什么,计算机中的操作系统的主要功能是什么
- 帆软报表写switch函数
- ikbc c104win键盘失灵以及数字键失灵
- RL(四)动态规划解决强化学习
- java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.c