ANR 输入超时
Posted
技术标签:
【中文标题】ANR 输入超时【英文标题】:ANR Input timed out 【发布时间】:2018-07-27 03:30:38 【问题描述】:输入调度超时(等待,因为没有窗口具有焦点,但有一个焦点应用程序可能最终在启动完成时添加一个窗口。)
嗨!我从几个用户那里收到了这个奇怪的 ANR 报告。不幸的是,我对 ANR 报告的了解非常有限,我希望有人可以帮助我了解造成这种情况的原因
"main" tid=1 Waiting
"main" prio=5 tid=1 Waiting
| group="main" sCount=1 dsCount=0 flags=1 obj=0x733b6610 self=0x7b2cebea00
| sysTid=5982 nice=-10 cgrp=default sched=0/0 handle=0x7bb1b3b9a8
| state=S schedstat=( 895549085 117045629 1679 ) utm=75 stm=13 core=7 HZ=100
| stack=0x7fc1071000-0x7fc1073000 stackSize=8MB
| held mutexes=
at java.lang.Object.wait (Native method)
- waiting on <0x06cee88a> (a java.lang.Object)
at java.lang.Thread.parkFor$ (Thread.java:2137)
- locked <0x06cee88a> (a java.lang.Object)
at sun.misc.Unsafe.park (Unsafe.java:358)
at java.util.concurrent.locks.LockSupport.park (LockSupport.java:190)
at java.util.concurrent.FutureTask.awaitDone (FutureTask.java:450)
at java.util.concurrent.FutureTask.get (FutureTask.java:192)
at android.os.AsyncTask.get (AsyncTask.java:542)
at trai.gov.in.dnd.app.DNDMasterActivityNEW.forceUpdateAppDialog (DNDMasterActivityNEW.java:281)
at trai.gov.in.dnd.app.DNDMasterActivityNEW.Init (DNDMasterActivityNEW.java:272)
at trai.gov.in.dnd.app.DNDMasterActivityNEW.onCreate (DNDMasterActivityNEW.java:92)
at android.app.Activity.performCreate (Activity.java:6999)
at android.app.Activity.performCreate (Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1589)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6494)
at java.lang.reflect.Method.invoke (Native method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
"AsyncTask #1" tid=12 Native Performing network I/O
"AsyncTask #1" prio=5 tid=12 Native
| group="main" sCount=1 dsCount=0 flags=1 obj=0x12dc0000 self=0x7b21fef800
| sysTid=6009 nice=10 cgrp=default sched=0/0 handle=0x7b176854f0
| state=S schedstat=( 226769531 4555214 150 ) utm=20 stm=1 core=7 HZ=100
| stack=0x7b17583000-0x7b17585000 stackSize=1037KB
| held mutexes=
#00 pc 000000000006a58c /system/lib64/libc.so (__ppoll+8)
#01 pc 00000000000264c0 /system/lib64/libc.so (poll+88)
#02 pc 000000000002ea78 /system/lib64/libjavacore.so (???)
#03 pc 0000000000236ad0 /system/framework/arm64/boot-core-libart.oat (Java_libcore_io_Linux_poll___3Landroid_system_StructPollfd_2I+160)
at libcore.io.Linux.poll (Native method)
at libcore.io.BlockGuardOs.poll (BlockGuardOs.java:216)
at libcore.io.IoBridge.isConnected (IoBridge.java:254)
at libcore.io.IoBridge.connectErrno (IoBridge.java:188)
at libcore.io.IoBridge.connect (IoBridge.java:130)
at java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java:129)
at java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:356)
- locked <0x0b28cfd7> (a java.net.SocksSocketImpl)
at java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect (SocksSocketImpl.java:357)
at java.net.Socket.connect (Socket.java:616)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket (PlainSocketFactory.java:124)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection (DefaultClientConnectionOperator.java:149)
at org.apache.http.impl.conn.AbstractPoolEntry.open (AbstractPoolEntry.java:169)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open (AbstractPooledConnAdapter.java:124)
at org.apache.http.impl.client.DefaultRequestDirector.execute (DefaultRequestDirector.java:366)
at org.apache.http.impl.client.AbstractHttpClient.execute (AbstractHttpClient.java:560)
at org.apache.http.impl.client.AbstractHttpClient.execute (AbstractHttpClient.java:492)
at org.apache.http.impl.client.AbstractHttpClient.execute (AbstractHttpClient.java:470)
at trai.gov.in.dnd.extras.Network.HttpCallToServer (Network.java:122)
at trai.gov.in.dnd.extras.AsyncNetworkWithID.doInBackground (AsyncNetworkWithID.java:32)
at trai.gov.in.dnd.extras.AsyncNetworkWithID.doInBackground (AsyncNetworkWithID.java:10)
at android.os.AsyncTask$2.call (AsyncTask.java:333)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run (AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
at java.lang.Thread.run (Thread.java:764)
【问题讨论】:
您可能正在应用程序的某个地方执行资源密集型任务。我不知道您的代码看起来如何,但我建议您使用线程来操纵花费在执行某些任务上的时间。 我应该在整个应用程序中使用线程 【参考方案1】:当主(主)线程中发生长时间操作时,会发生 ANR。如果此线程很忙,Android 将无法处理应用程序中的任何其他 GUI 事件,从而引发 ANR 对话框。
很明显,您的部分代码占用了大量资源或需要时间来完成。这就是导致您的应用抛出 ANR 的原因。
检查您的DNDMasterActivityNEW.java
课程,您的输入发送有延迟。有几种方法可以解决这个问题:
progressbar
指示调度何时进行,并在调度完成后将可见性设置为“GONE”。
使用不同的线程进行调度。
找到一种更节省时间的替代方法,以替代您当前用于分派输入的方法。
如果您仍然无法解决问题,请发布您的DNDMasterActivityNEW.java
代码。
【讨论】:
以上是关于ANR 输入超时的主要内容,如果未能解决你的问题,请参考以下文章