【朝花夕拾】Android性能篇之(八)ANR篇--草稿
2024-08-23 01:46:28
1、ANR概念
2、ANR发生场景
Android开发者官网 上说到了两个原因:(1)点击按键或者触摸屏幕等输入事件在5s内没有响应;(2)10s内没有完成广播事件。如下所示:
Android will display the ANR dialog for a particular application when it detects one of the following conditions: ● No response to an input event (such as key press or screen touch events) within 5 seconds.
● A BroadcastReceiver hasn't finished executing within 10 seconds.
当时坊间给出的原因更多
(1)点击按键或者触摸屏幕等输入事件在5s内没有响应。
(2)BroadcastReceiver事件(onReceive(...)方法)在规定的时间内没有处理完(前台广播为10s,后台广播为60s)。
前台广播
将flag设置为Intent.FLAG_RECEIVER_FOREGROUND,该广播将成为前台广播。当发送广播时,会允许接收者以前台的优先级运行,有更段的时间间隔,可以减少接收延迟。如下所示:
Intent mIntent = new Intent(string action);
mIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
mContext.sendBroadcast(mIntent);
后台广播
正常广播的接收者为后台优先级,即默认为后台广播,不会被自动提升。或者是将flag设置为Intent.FLAG_FROM_BACKGROUND,将Intent标识为来自后台的操作,而不是用户的交互行为。
(3)Service在规定时间内没有完成启动(前台Service为20s,后台Service为200s)。
(4)ContentProvider的publish在10s内没有完成。
最新文章
- 51Nod 算法马拉松21(迎新年)
- SharePoint 2013 入门教程之创建及修改母版页
- mysql的故事
- 使用jQuery基本过滤选择器
- CentOS 7.0系统安装配置图解教程
- 关于es6的箭头函数使用与内部this指向
- BZOJ1978: [BeiJing2010]取数游戏 game
- (php)生成指定个数的随机红包
- UINavigationController的横屏问题
- 在JBuilder8在使用ANT
- svn checkout The XML response contains invalid XML
- 【PAT】B1005 继续(3n+1)猜想
- mysql linux安装教程
- angular7 + d3 显示svg
- every day a practice —— morning(4)
- Eclipse远程连接HBase
- Hibernate笔记③--集合映射、组合映射、联合主键、查询案例
- 微信小程序从子页面退回父页面时的数据传递 wx.navigateBack()
- vcenter安装错误The DSN is pointing to anunspported ODBC driver...
- TensorFlow实现线性回归