为什么安卓在 ANR 中处理应用程序时,它在循环器中等待



在我的安卓日志中,我看到:

01-02 02:01:46.523 E/ActivityManager(  459): ANR in com.android.phone (com.android.phone/.InCallScreen)

然后当我转到/data/anr/traces.txt 时,我看到

Cmd line: com.android.phone
DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0)
"main" prio=5 tid=1 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x410f7508 self=0x40eeeb68
  | sysTid=649 nice=0 sched=0/0 cgrp=apps handle=1075429168
  | schedstat=( 0 0 0 ) utm=1361 stm=314 core=1
  #00  pc 0000dac0  /system/lib/libc.so (epoll_wait+12)
  #01  pc 00014899  /system/lib/libutils.so (android::Looper::pollInner(int)+96)
  #02  pc 00014b01  /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+104)
  #03  pc 00063aeb  /system/lib/libandroid_runtime.so (android::NativeMessageQueue::pollOnce(_JNIEnv*, int)+22)
  #04  pc 0001df30  /system/lib/libdvm.so (dvmPlatformInvoke+112)
  #05  pc 0004d1fb  /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+394)
  #06  pc 00038f4d  /system/lib/libdvm.so (dvmCheckCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+8)
  #07  pc 00000214  /dev/ashmem/dalvik-jit-code-cache (deleted)
  at android.os.MessageQueue.nativePollOnce(Native Method)
  at android.os.MessageQueue.next(MessageQueue.java:125)
  at android.os.Looper.loop(Looper.java:124)
  at android.app.ActivityThread.main(ActivityThread.java:4921)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
  at dalvik.system.NativeStart.main(Native Method)

我的问题是,当堆栈跟踪显示 Looper 中的主线程等待消息时,为什么 android 认为该应用程序处于 ANR 中? 这对我来说似乎很正常。我知道安卓在主线程下载某些内容/执行长时间操作时显示 ANR。但它在等待消息似乎很正常。如果我错了,请纠正我。

我发现了这个有趣的错误报告:

http://code.google.com/p/android/issues/detail?id=41755

简短的总结是,NDK 包装器代码中似乎存在一个错误,这意味着来自多个来源的事件可能会导致 ANR。这完全符合我的用例---我有一个 NDK 应用程序,其中工作发生在后台线程和游戏手柄中,并且我得到的 ANR 与您描述的 ANR 和错误报告中的 ANR 完全匹配。

这与您的设置相似吗?

更新:更多信息:http://ps3computing.blogspot.co.uk/2012/12/anr-application-not-responding.html

应用了他博客上描述的修复程序后,我似乎无法再次使 ANR 显示出来。不过,这并不是说它已经消失了...

最新更新