本文站在系统角度来简单总结下ANR分析的一般套路。
一、ANR简介
1.1 ANR定义
ANR(Application Not Responding):即应用无响应。主线程在超时时间内没有做完特定的事情,就会发生ANR。
1.2 ANR类型
1)KeyDispatchTimeout-主要类型按键或触摸事件,input事件在5S内没有处理完成发生ANR
日志关键字:Reason: Input dispatching timed out xxxx
2)ServiceTimeout-bind,create,start,unbind等在主线程处理耗时,前台Service在20s内,后台Service在200s内没有处理完成发生ANR
日志关键字:Timeout executing service:/executing service XXX
3)BroadcastTimeout- BroadcastReceiver onReceiver处理事务时前台广播在10S内,后台广播在60s内没有处理完成发生ANR
日志关键字:Timeout of broadcast XXX/Receiver during timeout:XXX/Broadcast of XXX
4)ProcessContentProviderPublishTimedOutLocked-ContentProvider publish在10s内没有处理完成发生ANR
日志关键字:timeout publishing content providers
1.3 造成ANR的常见原因
主线程耗时操作,如复杂的layout,庞大的for循环,IO等。
主线程被子线程同步锁block<