我遇到了应用冻结的一些问题。看起来它与hardwarerenderer有关,也许与我正在使用的线程数量有关。我喜欢有人看看日志,并告诉我是否有任何明显的指出。感谢。
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=0x401f6600 self=0x125f8
| sysTid=15811 nice=0 sched=0/0 cgrp=default handle=-1345129368
| schedstat=( 0 0 0 ) utm=2495 stm=1172 core=0
at com.google.android.gles_jni.EGLImpl.eglSwapBuffers(Native Method)
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:648)
at android.view.ViewRoot.draw(ViewRoot.java:1594)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1410)
at android.view.ViewRoot.handleMessage(ViewRoot.java:2040)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
"Thread-811" prio=5 tid=31 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x412479c0 self=0x45e478
| sysTid=17073 nice=0 sched=0/0 cgrp=default handle=2020736
| schedstat=( 0 0 0 ) utm=4 stm=0 core=1
"Thread-810" prio=5 tid=29 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x41296560 self=0x4d2f38
| sysTid=17072 nice=0 sched=0/0 cgrp=default handle=10050328
| schedstat=( 0 0 0 ) utm=3 stm=1 core=1
"Thread-809" prio=5 tid=28 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x4129b490 self=0x45e710
| sysTid=17071 nice=0 sched=0/0 cgrp=default handle=5146952
| schedstat=( 0 0 0 ) utm=3 stm=0 core=0
"Thread-808" prio=5 tid=27 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x412d6008 self=0x44aa48
| sysTid=17070 nice=0 sched=0/0 cgrp=default handle=3737640
| schedstat=( 0 0 0 ) utm=2 stm=0 core=0
"Thread-807" prio=5 tid=26 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x41352300 self=0x3abee0
| sysTid=17069 nice=0 sched=0/0 cgrp=default handle=5418280
| schedstat=( 0 0 0 ) utm=3 stm=0 core=1
"Thread-806" prio=5 tid=25 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x41352a00 self=0x4d0a00
| sysTid=17068 nice=0 sched=0/0 cgrp=default handle=5327520
| schedstat=( 0 0 0 ) utm=3 stm=0 core=1
"Thread-805" prio=5 tid=24 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x41352ef0 self=0x49bec8
| sysTid=17067 nice=0 sched=0/0 cgrp=default handle=6587488
| schedstat=( 0 0 0 ) utm=3 stm=0 core=1
"Thread-804" prio=5 tid=23 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x4138be18 self=0x4e2c18
| sysTid=17066 nice=0 sched=0/0 cgrp=default handle=9299592
| schedstat=( 0 0 0 ) utm=3 stm=0 core=1
"Thread-803" prio=5 tid=22 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x4138e5e0 self=0x483e58
| sysTid=17065 nice=0 sched=0/0 cgrp=default handle=8949624
| schedstat=( 0 0 0 ) utm=4 stm=0 core=0
"Thread-802" prio=5 tid=21 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x4151b210 self=0x4b23d0
| sysTid=17064 nice=0 sched=0/0 cgrp=default handle=4798984
| schedstat=( 0 0 0 ) utm=3 stm=0 core=0
"Thread-801" prio=5 tid=20 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x4151d118 self=0x492bd0
| sysTid=17063 nice=0 sched=0/0 cgrp=default handle=10231792
| schedstat=( 0 0 0 ) utm=3 stm=0 core=0
"Thread-800" prio=5 tid=19 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x416cf1f8 self=0x482808
| sysTid=17062 nice=0 sched=0/0 cgrp=default handle=1742184
| schedstat=( 0 0 0 ) utm=4 stm=0 core=1
"Thread-799" prio=5 tid=18 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x416daed8 self=0x488218
| sysTid=17061 nice=0 sched=0/0 cgrp=default handle=4954264
| schedstat=( 0 0 0 ) utm=3 stm=1 core=0
"Thread-798" prio=5 tid=17 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x40850ce8 self=0x4a9a28
| sysTid=17060 nice=0 sched=0/0 cgrp=default handle=5096688
| schedstat=( 0 0 0 ) utm=5 stm=0 core=0
"Thread-797" prio=5 tid=16 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x40870490 self=0x39e6e8
| sysTid=17059 nice=0 sched=0/0 cgrp=default handle=6489784
| schedstat=( 0 0 0 ) utm=6 stm=0 core=0
"Thread-796" prio=5 tid=15 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x40941f78 self=0x399aa8
| sysTid=17058 nice=0 sched=0/0 cgrp=default handle=8600264
| schedstat=( 0 0 0 ) utm=6 stm=0 core=0
"Thread-795" prio=5 tid=14 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x4102be68 self=0x1700b8
| sysTid=17057 nice=0 sched=0/0 cgrp=default handle=9814600
| schedstat=( 0 0 0 ) utm=5 stm=0 core=1
"Thread-794" prio=5 tid=13 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x41082f70 self=0x1f78d0
| sysTid=17056 nice=0 sched=0/0 cgrp=default handle=7060200
| schedstat=( 0 0 0 ) utm=4 stm=0 core=1
"Thread-793" prio=5 tid=12 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x410dcbf0 self=0x2ef6a0
| sysTid=17055 nice=0 sched=0/0 cgrp=default handle=7993768
| schedstat=( 0 0 0 ) utm=4 stm=0 core=0
"Thread-792" prio=5 tid=11 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x4113a620 self=0x5edf28
| sysTid=17054 nice=0 sched=0/0 cgrp=default handle=7291408
| schedstat=( 0 0 0 ) utm=6 stm=0 core=0
"Thread-791" prio=5 tid=10 VMWAIT
| group="main" sCount=1 dsCount=0 obj=0x4084c0a0 self=0x5c6b28
| sysTid=17053 nice=0 sched=0/0 cgrp=default handle=6171632
| schedstat=( 0 0 0 ) utm=6 stm=0 core=0
"AsyncTask #5" prio=5 tid=767 WAIT
| group="main" sCount=1 dsCount=0 obj=0x410cbcb0 self=0x85fca0
| sysTid=16758 nice=10 sched=0/0 cgrp=bg_non_interactive handle=10617808
| schedstat=( 0 0 0 ) utm=12 stm=0 core=0
at java.lang.Object.wait(Native Method)
- waiting on <0x410cbe80> (a java.lang.VMThread) tid=767
at java.lang.Thread.parkFor(Thread.java:1425)
at java.lang.LangAccessImpl.parkFor(LangAccessImpl.java:48)
at sun.misc.Unsafe.park(Unsafe.java:329)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1014)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
at java.lang.Thread.run(Thread.java:1020)
"AsyncTask #4" prio=5 tid=766 WAIT
| group="main" sCount=1 dsCount=0 obj=0x4101c710 self=0x9e6ca8
| sysTid=16757 nice=10 sched=0/0 cgrp=bg_non_interactive handle=10383448
| schedstat=( 0 0 0 ) utm=36 stm=0 core=0
at java.lang.Object.wait(Native Method)
- waiting on <0x41079430> (a java.lang.VMThread) tid=766
at java.lang.Thread.parkFor(Thread.java:1425)
at java.lang.LangAccessImpl.parkFor(LangAccessImpl.java:48)
at sun.misc.Unsafe.park(Unsafe.java:329)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1014)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
at java.lang.Thread.run(Thread.java:1020)
"AsyncTask #5" prio=5 tid=765 WAIT
| group="main" sCount=1 dsCount=0 obj=0x410a9788 self=0x7c0cd0
| sysTid=16738 nice=10 sched=0/0 cgrp=bg_non_interactive handle=2062320
| schedstat=( 0 0 0 ) utm=5 stm=0 core=1
at java.lang.Object.wait(Native Method)
- waiting on <0x41352368> (a java.lang.VMThread) tid=765
at java.lang.Thread.parkFor(Thread.java:1425)
at java.lang.LangAccessImpl.parkFor(LangAccessImpl.java:48)
at sun.misc.Unsafe.park(Unsafe.java:329)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1014)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
at java.lang.Thread.run(Thread.java:1020)
"AsyncTask #4" prio=5 tid=411 WAIT
| group="main" sCount=1 dsCount=0 obj=0x415f0098 self=0x779eb8
| sysTid=16372 nice=10 sched=0/0 cgrp=bg_non_interactive handle=7993152
| schedstat=( 0 0 0 ) utm=47 stm=2 core=0
at java.lang.Object.wait(Native Method)
- waiting on <0x4113ed48> (a java.lang.VMThread) tid=411
at java.lang.Thread.parkFor(Thread.java:1425)
at java.lang.LangAccessImpl.parkFor(LangAccessImpl.java:48)
at sun.misc.Unsafe.park(Unsafe.java:329)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1014)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
at java.lang.Thread.run(Thread.java:1020)
"AsyncTask #3" prio=5 tid=410 WAIT
| group="main" sCount=1 dsCount=0 obj=0x411276c8 self=0x66bb20
| sysTid=16371 nice=10 sched=0/0 cgrp=bg_non_interactive handle=7590640
| schedstat=( 0 0 0 ) utm=125 stm=1 core=1
at java.lang.Object.wait(Native Method)
- waiting on <0x41127860> (a java.lang.VMThread) tid=410
at java.lang.Thread.parkFor(Thread.java:1425)
at java.lang.LangAccessImpl.parkFor(LangAccessImpl.java:48)
at sun.misc.Unsafe.park(Unsafe.java:329)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObj...
答案 0 :(得分:7)
ANR是众所周知的问题。确保您在AsyncTask中执行所有昂贵的操作,并且不要对onCreate,onStart或onResume活动负担过重。
请查看Responsiveness以获取更多信息。
特别是,活动应尽可能少地设置关键生命周期方法,如onCreate()和onResume()。潜在的长时间运行操作(如网络或数据库操作)或计算上昂贵的计算(如调整位图大小)应在子线程中完成(或者在数据库操作的情况下,通过异步请求)。但是,这并不意味着您的主线程在等待子线程完成时应该阻塞 - 也不应该调用Thread.wait()或Thread.sleep()。在等待子线程完成时,您的主线程应该为子线程提供一个Handler,以便在完成时回发。以这种方式设计应用程序将允许主线程保持对输入的响应,从而避免由5秒输入事件超时引起的ANR对话框。对于显示UI的任何其他线程,应遵循这些相同的做法,因为它们也受到相同的超时。
答案 1 :(得分:0)
我发现了其中一个ANR错误的非常具体的原因。
在我的应用程序的一个布局定义中,我设置了android:layout_alignRight =“fieldX”
但是在fieldX的定义中,我有了android:visibility =“gone”。
因此显示器试图将字段与不可见的字段对齐。
通过取出fieldX定义的android:visibility线,应用程序开始正常工作而不会挂起。