zoukankan      html  css  js  c++  java
  • 【朝花夕拾】Android性能篇之(八)ANR篇--草稿

    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,该广播将成为前台广播。当发送广播时,会允许接收者以前台的优先级运行,有更段的时间间隔,可以减少接收延迟。如下所示:

    1  Intent mIntent = new Intent(string action);                                 
    2  mIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); 
    3  mContext.sendBroadcast(mIntent); 

    后台广播

      正常广播的接收者为后台优先级,即默认为后台广播,不会被自动提升。或者是将flag设置为Intent.FLAG_FROM_BACKGROUND,将Intent标识为来自后台的操作,而不是用户的交互行为。

      (3)Service在规定时间内没有完成启动(前台Service为20s,后台Service为200s)。

      (4)ContentProvider的publish在10s内没有完成。

  • 相关阅读:
    mysql自动备份shell
    程序员,架构师有话对你说
    Chief Technology Officer
    读《对软件开发的一点心得体会》有感
    shell编程值之shell流程控制(7)
    shell编程值之正则表达式与字符截取(6)
    shell编程之环境变量配置文件(4)
    shell编程之运算符(3)
    shell编程之BASH变量(2)
    shell编程之SHELL基础(1)
  • 原文地址:https://www.cnblogs.com/andy-songwei/p/10148388.html
Copyright © 2011-2022 走看看