ANR(Application Not responding),是指应用程序未响应,Android系统对于一些事件需要在一定的时间范围内完成,如果超过预定时间能未能得到有效响应或者响应时间过长,都会造成ANR。一般地,这时往往会弹出一个提示框,告知用户当前xxx未响应,用户可选择继续等待或者Force Close。
ANR主要有4类:
- Service Timeout:
对于前台服务,则超时为SERVICE_TIMEOUT = 20s;
对于后台服务,则超时为SERVICE_BACKGROUND_TIMEOUT = 200s
- BroadcastQueue Timeout
对于前台广播,则超时为BROADCAST_FG_TIMEOUT = 10s;
对于后台广播,则超时为BROADCAST_BG_TIMEOUT = 60s
- ContentProvider Timeout:内容提供者,在publish过超时10s;
ContentProvider 超时为CONTENT_PROVIDER_PUBLISH_TIMEOUT = 10s. 这个跟前面的Service和BroadcastQueue完全不同, 由Provider进程启动过程相关.
- InputDispatching Timeout:
- 无窗口, 有应用:Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.
- 窗口暂停: Waiting because the
[targetType]window is paused. - 窗口未连接: Waiting because the
[targetType]window’s input channel is not registered with the input dispatcher. The window may be in the process of being removed. - 窗口连接已死亡:Waiting because the
[targetType]window’s input connection is[Connection.Status]. The window may be in the process of being removed. - 窗口连接已满:Waiting because the
[targetType]window’s input channel is full. Outbound queue length:[outboundQueue长度]. Wait queue length:[waitQueue长度]. - 按键事件,输出队列或事件等待队列不为空:Waiting to send key event because the
[targetType]window has not finished processing all of the input events that were previously delivered to it. Outbound queue length:[outboundQueue长度]. Wait queue length:[waitQueue长度]. - 非按键事件,事件等待队列不为空且头事件分发超时500ms:Waiting to send non-key event because the
[targetType]window has not finished processing certain input events that were delivered to it over 500ms ago. Wait queue length:[waitQueue长度]. Wait queue head age:[等待时长].
本文深入探讨了Android系统中ANR(Application Not Responding)现象的原因和类型,包括Service、BroadcastQueue、ContentProvider及InputDispatching的超时机制,帮助开发者理解和解决应用卡顿问题。
3043

被折叠的 条评论
为什么被折叠?



