Android ANR这个错误大家并不陌生,但是从Android 2.2开始出错的ANR信息会自动上传给Google进行系统分析改进,当然了你的应用ANR错误其实保存在一个文件中,在/data/anr/traces.txt文件中,如果你的Android设备没有Root越狱过,可以将你的软件装在模拟器上分析,模拟器可以直接使用Eclipse中的DDMS里的File Explorer来打开,如下图:
虽然traces.txt是一个文本文件,不过使用windows上的记事本打开可能无法正常处理linux的换行符,这里Android123建议你使用ultra edit查看,当然了使用Windows自带的写字板也是不错的。下面一起来分析下错误吧,第一行为出错的时间,第二行都会写上发生ANR的package Name,下文是com.android.systemui这个包,里面的部分线程出了问题,通过下面的的xxx方法以及对应的java文件,后面的数字为xxx.java文件的第几行,是不是很方便呢?
----- pid 125 at 2011-02-22 05:18:01 -----
Cmd line: com.android.systemui
DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x4001f1a8 self=0xce48
| sysTid=125 nice=0 sched=0/0 cgrp=default handle=-1345006528
| schedstat=( 981213067 8042604425 151 )
at android.os.BinderProxy.transact(Native Method)
at android.os.storage.IMountService$Stub$Proxy.isUsbMassStorageConnected(IMountService.java:95)
at android.os.storage.StorageManager.isUsbMassStorageConnected(StorageManager.java:385)
at com.android.systemui.usb.StorageNotification.<init>(StorageNotification.java:71)
at com.android.systemui.statusbar.policy.StatusBarPolicy.<init>(StatusBarPolicy.java:412)
at com.android.systemui.statusbar.StatusBarService.onCreate(StatusBarService.java:239)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1920)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:982)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3647)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
"Binder Thread #2" prio=5 tid=8 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40511270 self=0x1c1100
| sysTid=153 nice=0 sched=0/0 cgrp=default handle=1141608
| schedstat=( 27181321 64708345 5 )
at dalvik.system.NativeStart.run(Native Method)
"Binder Thread #1" prio=5 tid=7 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x405111a8 self=0x1349c8
| sysTid=152 nice=0 sched=0/0 cgrp=default handle=1264008
| schedstat=( 31857510 74284459 5 )
at dalvik.system.NativeStart.run(Native Method)
"Compiler" daemon prio=5 tid=6 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x4050dd10 self=0x116538
| sysTid=144 nice=0 sched=0/0 cgrp=default handle=982520
| schedstat=( 7319346 103454345 12 )
at dalvik.system.NativeStart.run(Native Method)
"JDWP" daemon prio=5 tid=5 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x4050dc60 self=0x116400
| sysTid=142 nice=0 sched=0/0 cgrp=default handle=986536
| schedstat=( 32876840 393298925 20 )
at dalvik.system.NativeStart.run(Native Method)
"Signal Catcher" daemon prio=5 tid=4 RUNNABLE
| group="system" sCount=0 dsCount=0 obj=0x4050dba0 self=0x253ab0
| sysTid=141 nice=0 sched=0/0 cgrp=default handle=2439792
| schedstat=( 94447996 796994478 19 )
at dalvik.system.NativeStart.run(Native Method)
"GC" daemon prio=5 tid=3 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x4050daf8 self=0x8fd40
| sysTid=128 nice=0 sched=0/0 cgrp=default handle=2439592
| schedstat=( 103352102 819201761 21 )
at dalvik.system.NativeStart.run(Native Method)
"HeapWorker" daemon prio=5 tid=2 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x4050da40 self=0xf0c70
| sysTid=127 nice=0 sched=0/0 cgrp=default handle=2439528
| schedstat=( 971134410 6445300652 103 )
at dalvik.system.NativeStart.run(Native Method)