17

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.

Melquiades
  • 8,496
  • 1
  • 31
  • 46
GuilhermeFGL
  • 2,891
  • 3
  • 15
  • 33
  • 2
    My first thoughts is are you doing all the work on the UI thread (thread overload), instead of starting new threads for intensive tasks ? Use AsyncTask class to do all the hard work on another thread. Maybe your device is working too hard on other things ? – Jon Goodwin Aug 23 '17 at 15:32
  • At my first example the error occur in `setContentView();`, how is one of the first lines in `onCreateView()`. Following the description of the error, overload the main thread was my first guess too, but Android Monitor don't point anything critical – GuilhermeFGL Aug 23 '17 at 16:09
  • Yes setContentView() is quite soon (but not the first method called). My "Maybe your device is working too hard on other things" means, other services for example, using up resources, but your using "Android Monitor" so you should see that (in the other tab from logcat). You say ".same error but in different places and different applications" That seems certainly a phone resource problem { cpu ? memory, space, swap problem] buy a better phone ;O) } .puzzling. – Jon Goodwin Aug 23 '17 at 16:53
  • I am receiving this errors from Play Store Console, from many devices and Android versions. Will update my question which that. – GuilhermeFGL Aug 23 '17 at 16:56
  • I update my question, but infertility Google Play Console don't provide much more information. – GuilhermeFGL Aug 24 '17 at 12:32
  • Same problem here – Denny Sep 15 '18 at 17:41
  • Are you storing very large amounts of data in shared preferences, by any chance? – clownba0t Oct 11 '18 at 12:38

1 Answers1

3

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..

hossam scott
  • 466
  • 5
  • 28