有人会请。帮我分析以下ANR为我的Android应用程序。我是ANR世界的新手。
DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0)
"main" prio=5 tid=1 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40ce24c0 self=0x185da18
| sysTid=2641 nice=0 sched=0/0 cgrp=default handle=1075160444
| schedstat=( 13982089096 731925534 8330 ) utm=1371 stm=27 core=0
at android.graphics.Paint.native_getTextRunAdvances(Native Method)
at android.graphics.Paint.getTextRunAdvances(Paint.java:1683)
at android.graphics.Paint.getTextRunAdvances(Paint.java:1649)
at android.text.MeasuredText.addStyleRun(MeasuredText.java:168)
at android.text.MeasuredText.addStyleRun(MeasuredText.java:200)
at android.text.StaticLayout.generate(StaticLayout.java:281)
at android.text.DynamicLayout.reflow(DynamicLayout.java:283)
at android.text.DynamicLayout.<init>(DynamicLayout.java:169)
at android.widget.TextView.makeSingleLayout(TextView.java:6471)
at android.widget.TextView.makeNewLayout(TextView.java:6369)
at android.widget.TextView.onMeasure(TextView.java:6715)
at android.view.View.measure(View.java:12790)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1374)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:663)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
at android.view.View.measure(View.java:12790)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1164)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.widget.ScrollView.onMeasure(ScrollView.java:312)
at android.view.View.measure(View.java:12790)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
at android.view.View.measure(View.java:12790)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.view.View.measure(View.java:12790)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:815)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
at android.view.View.measure(View.java:12790)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2218)
at android.view.View.measure(View.java:12790)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1147)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2642)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4624)
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:965)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:732)
at dalvik.system.NativeStart.main(Native Method)
"Thread-275" prio=5 tid=19 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x419c17e8 self=0x1bc3948
| sysTid=2679 nice=0 sched=0/0 cgrp=default handle=28864560
| schedstat=( 14379768 4029537 49 ) utm=0 stm=1 core=1
at dalvik.system.NativeStart.run(Native Method)
"AsyncTask #2" prio=5 tid=18 WAIT
| group="main" sCount=1 dsCount=0 obj=0x41846738 self=0x1a5ae10
| sysTid=2678 nice=10 sched=0/0 cgrp=bg_non_interactive handle=28757152
| schedstat=( 373307 159769 2 ) utm=0 stm=0 core=1
at java.lang.Object.wait(Native Method)
- waiting on <0x41841e48> (a java.lang.VMThread) held by tid=18 (AsyncTask #2)
at java.lang.Thread.parkFor(Thread.java:1231)
at sun.misc.Unsafe.park(Unsafe.java:323)
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:1009)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1069)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
"Thread-271" prio=5 tid=17 TIMED_WAIT
| group="main" sCount=1 dsCount=0 obj=0x419ae098 self=0x1b56b98
| sysTid=2674 nice=0 sched=0/0 cgrp=default handle=28672672
| schedstat=( 21873077 12209999 79 ) utm=2 stm=0 core=1
at java.lang.Object.wait(Native Method)
- waiting on <0x419aaf98> (a com.google.ads.internal.c)
at java.lang.Object.wait(Object.java:401)
at com.google.ads.internal.c.run(SourceFile:756)
at java.lang.Thread.run(Thread.java:856)
"Thread-268" prio=5 tid=12 TIMED_WAIT
| group="main" sCount=1 dsCount=0 obj=0x4198b428 self=0x1b35a88
| sysTid=2671 nice=0 sched=0/0 cgrp=default handle=28578968
| schedstat=( 24263467 36899769 115 ) utm=0 stm=2 core=0
at java.lang.Object.wait(Native Method)
- waiting on <0x41986178> (a com.google.ads.internal.c)
at java.lang.Object.wait(Object.java:401)
at com.google.ads.internal.c.run(SourceFile:756)
at java.lang.Thread.run(Thread.java:856)
"AsyncTask #1" prio=5 tid=14 WAIT
| group="main" sCount=1 dsCount=0 obj=0x4146c868 self=0x1ab9608
| sysTid=2665 nice=10 sched=0/0 cgrp=bg_non_interactive handle=28020336
| schedstat=( 5055464 9107460 14 ) utm=0 stm=0 core=1
at java.lang.Object.wait(Native Method)
- waiting on <0x41828438> (a java.lang.VMThread) held by tid=14 (AsyncTask #1)
at java.lang.Thread.parkFor(Thread.java:1231)
at sun.misc.Unsafe.park(Unsafe.java:323)
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:1009)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1069)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
"CookieSyncManager" prio=5 tid=13 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x41848f90 self=0x1a91248
| sysTid=2663 nice=10 sched=0/0 cgrp=bg_non_interactive handle=27888536
| schedstat=( 3302152 6325925 8 ) utm=0 stm=0 core=1
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:122)
at android.os.Looper.loop(Looper.java:135)
at android.webkit.WebSyncManager.run(WebSyncManager.java:90)
at android.webkit.CookieSyncManager.run(CookieSyncManager.java:61)
at java.lang.Thread.run(Thread.java:856)
"WebViewCoreThread" prio=5 tid=11 WAIT
| group="main" sCount=1 dsCount=0 obj=0x41888dc8 self=0x1a8e838
| sysTid=2661 nice=0 sched=0/0 cgrp=default handle=27846328
| schedstat=( 313471591 130332562 1238 ) utm=23 stm=8 core=0
at java.lang.Object.wait(Native Method)
- waiting on <0x41987fe8> (a android.webkit.CallbackProxy)
at java.lang.Object.wait(Object.java:364)
at android.webkit.CallbackProxy.shouldOverrideUrlLoading(CallbackProxy.java:1001)
at android.webkit.BrowserFrame.handleUrl(BrowserFrame.java:654)
at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)
at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:113)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:738)
at java.lang.Thread.run(Thread.java:856)
"Binder Thread #3" prio=5 tid=10 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x41456440 self=0x1a28a50
| sysTid=2654 nice=0 sched=0/0 cgrp=default handle=27429392
| schedstat=( 1705920 9067694 8 ) utm=0 stm=0 core=0
at dalvik.system.NativeStart.run(Native Method)
"Binder Thread #2" prio=5 tid=9 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x41455b48 self=0x1a27af0
| sysTid=2653 nice=0 sched=0/0 cgrp=default handle=27416912
| schedstat=( 1736770 15136000 10 ) utm=0 stm=0 core=0
at dalvik.system.NativeStart.run(Native Method)
"Binder Thread #1" prio=5 tid=8 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x41452350 self=0x1a25040
| sysTid=2652 nice=0 sched=0/0 cgrp=default handle=27413984
| schedstat=( 7733459 8833156 18 ) utm=0 stm=0 core=1
at dalvik.system.NativeStart.run(Native Method)
"FinalizerWatchdogDaemon" daemon prio=5 tid=7 TIMED_WAIT
| group="main" sCount=1 dsCount=0 obj=0x4143ad08 self=0x1a247d8
| sysTid=2651 nice=0 sched=0/0 cgrp=default handle=26970456
| schedstat=( 239845 2467077 4 ) utm=0 stm=0 core=0
at java.lang.VMThread.sleep(Native Method)
at java.lang.Thread.sleep(Thread.java:1031)
at java.lang.Thread.sleep(Thread.java:1013)
at java.lang.Daemons$FinalizerWatchdogDaemon.run(Daemons.java:213)
at java.lang.Thread.run(Thread.java:856)
"FinalizerDaemon" daemon prio=5 tid=6 WAIT
| group="main" sCount=1 dsCount=0 obj=0x4143abb0 self=0x1a24388
| sysTid=2650 nice=0 sched=0/0 cgrp=default handle=26968904
| schedstat=( 1796155 2710308 9 ) utm=0 stm=0 core=1
at java.lang.Object.wait(Native Method)
- waiting on <0x40cd85d0> (a java.lang.ref.ReferenceQueue)
at java.lang.Object.wait(Object.java:401)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:102)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:73)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)
at java.lang.Thread.run(Thread.java:856)
"ReferenceQueueDaemon" daemon prio=5 tid=5 WAIT
| group="main" sCount=1 dsCount=0 obj=0x4143aa48 self=0x1a23f38
| sysTid=2649 nice=0 sched=0/0 cgrp=default handle=27400544
| schedstat=( 958695 2574075 22 ) utm=0 stm=0 core=0
at java.lang.Object.wait(Native Method)
- waiting on <0x40cd84f8>
at java.lang.Object.wait(Object.java:364)
at java.lang.Daemons$ReferenceQueueDaemon.run(Daemons.java:128)
at java.lang.Thread.run(Thread.java:8...
答案 0 :(得分:2)
只是不要在UI线程上运行很长时间(或者某些情况下可能很长的事情)。
这包括:数据库操作,互联网操作,复杂计算,大型存储操作(如编写大文件),......
每个操作都可以在asyncTask,新线程,带线程的服务,intentService,syncAdapter,线程池等运行......
操作完成后,您可以使用Handler对象告诉UI所有内容已完成。
答案 1 :(得分:0)
通常,如果应用程序无法响应用户输入,则会发生ANR。最常见的情况是在主UI线程中执行一些升沉任务。这些任务会阻碍工作流程,从而产生ANR。
要解决此问题,您应该使用不同的线程而不是UI线程来执行繁重的任务。您可以使用不同的工作线程,AsyncTask或将Runnable发布到处理程序来执行任务。
要了解有关ANR的详细信息并解决此问题,请nice article
答案 2 :(得分:0)
ANR
可能由以下原因引起:
首先在您的日志中搜索'timeout'
关键字,然后我才能帮助您