Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ANR - Input dispatching timed out

I have started receiving several strange ANR-report (Application Not Responding) from many code locations.

Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)

This ANR is popping up always in different places in my code, and they follow no logical pattern. I started receiving those errors around a month ago.

There are some examples of ANR reports and his respective code line:

at android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:139)
at br.com.xxx.xxx.activities.MainActivity.onCreate (MainActivity.java:71)
at android.app.Activity.performCreate (Activity.java:6245)

MainActivity.java:71: setContentView(R.layout.activity_main);

Another example:

at android.support.v4.app.BackStackRecord.replace (BackStackRecord.java:421)
at br.com.xxx.xxx.activities.MainActivity.openFragment (MainActivity.java:146)
at br.com.xxx.xxx.activities.MainActivity.openMenu (MainActivity.java:121)

                       currentFragment = new CardsFragment();
MainActivity.java:146: openFragment(currentFragment);

And that one doesn't even have a reference in to code:

  at java.lang.Object.wait! (Native method)
- waiting on <0x0a7b02dc> (a java.lang.Object)
  at java.lang.Thread.parkFor$ (Thread.java:1220)
- locked <0x0a7b02dc> (a java.lang.Object)
  at sun.misc.Unsafe.park (Unsafe.java:299)
  at java.util.concurrent.locks.LockSupport.park (LockSupport.java:158)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt (AbstractQueuedSynchronizer.java:810)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly (AbstractQueuedSynchronizer.java:971)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly (AbstractQueuedSynchronizer.java:1278)
  at java.util.concurrent.CountDownLatch.await (CountDownLatch.java:203)
  at android.app.SharedPreferencesImpl$EditorImpl$1.run (SharedPreferencesImpl.java:366)
  at android.app.QueuedWork.waitToFinish (QueuedWork.java:88)
  at android.app.ActivityThread.handleStopService (ActivityThread.java:3065)
  at android.app.ActivityThread.-wrap21 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1457)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:148)
  at android.app.ActivityThread.main (ActivityThread.java:5443)
  at java.lang.reflect.Method.invoke! (Native method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:728)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:618)

My question is: there is are a bunch of ANR reporting the same error but in different places and different applications. How do I resolve this error? Or I have to consider all those errors as different isolated errors?

I know there are already questions with this theme, but no one has yet given a helpful answer. At least none that could help me.

Edit: I am receiving those errors from many devices and Android versions:

  • Motorola Moto G (2nd Gen) (titan_umtsds), 1024MB RAM, Android 6.0
  • Samsung Galaxy Win2 (coreprimeltedtv), 1024MB RAM, Android 5.0
  • Motorola Moto G (1st Gen) (falcon_umts), 2048MB RAM, Android 7.1

Unfortunately, Google Play Console doesn't provide much more information.

like image 305
GuilhermeFGL Avatar asked Aug 21 '17 13:08

GuilhermeFGL


1 Answers

Your issue is occurring in Handler, which means it's happening on the main thread. You should call all billing processor methods on an IO thread to avoid blocking your main thread.

There are literally too many possible ways to do this to describe succinctly. AsyncTasks, RxJava, vanilla Threads, Android Service, etc..

like image 70
hossam scott Avatar answered Nov 04 '22 10:11

hossam scott