Input dispatching timed out 导致anr问题分析

 在这里的时候,应用主线程已经开始启动我们的目标窗口了,那肯定是进到我们应用当中了,那窗口为什么没有呢?再联系一下trace.txt当中的调用栈信息,肯定是我们在Activity的onResume方法当中逻辑耗时太久,导致WindowManagerService没有成功添加Activity的窗口,所以事件找不到目标,无法分发,所以产生ANR了。好了,这是我们的一个判断,那我们还需要找证据。事件分发,我们找一下InputDispatcher关键字,可以找到如下的信息:

07-06 19:13:27.781 18431 19430 D SettingsInterface:  from settings cache , name = sys_storage_threshold_max_bytes , value = null
07-06 19:13:27.813 18431 18597 I InputDispatcher: Application is not responding: AppWindowToken{34356a0 token=Token{8c7dc0f ActivityRecord{32a3d6e u0 com.google.android.apps.maps/com.google.android.maps.MapsActivity, isShadow:false t2134}}}.  It has been 8004.7ms since event, 8002.9ms since wait started.  Reason: Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.
07-06 19:13:27.827 18431 18597 I WindowManager: Input event dispatching timed out sending to application AppWindowToken{34356a0 token=Token{8c7dc0f ActivityRecord{32a3d6e u0 com.google.android.apps.maps/com.google.android.maps.MapsActivity, isShadow:false t2134}}}.  Reason: Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.

     可以明显看到,在开始创建窗口,到大约6秒后,系统已经开始分发事件了,此时已经发现没有目标窗口,系统此时已经提醒我们一次了,当然后边呢,目标窗口还是没有创建好,最终就导致ANR了,所以方法就很明确了,就是在我们应用的onNewIntent方法启动Activity时(Instrumentation.callActivityOnNewIntent),执行了耗时逻辑,最终导致了ANR的发生,因为这里的应用是google地图,没有源码,所以无法往下分析,也只是给大家点个思路,大家以后如果有这样的bug,可以顺着这个思路展开。
 

转载于:https://my.oschina.net/u/920274/blog/3061722

你可能感兴趣的:(Input dispatching timed out 导致anr问题分析)