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