ANR in com.android.launcher after tapping back -


when install app on devices (seems 4.4.4 , later) see following anr in com.android.launcher after following steps:

  1. from activity a, launch activity b
  2. in activity b, press system key , in onbackpressed() method of activity b relaunch activity (code below).
  3. system key remains in pressed state 5 seconds, screen turns black, app gets closed , launcher comes up. investigating logs shows anr in launcher process.

anr in com.android.launcher (com.android.launcher/com.android.launcher2.launcher) reason: input dispatching timed out (waiting because no window has focus there focused application may add window when finishes starting up.)

notice anr occurring in com.android.launcher (not in app).

btw, not doing expensive operation in onbackpressed/onpause/onstop methods.

the logs show onbackpressed() not being invoked when anr occurs - odd behavior can see here:

## user starts activity android launcher d/activity a: onresume() d/activity a: onclick(): start activity b d/activity a: onpause() d/activity b: onresume()  ## user taps system key (and onbackpressed() launches activity a) d/activity b: onbackpressed(): start activity d/activity b: onpause() d/activity a: onresume() d/activity a: onclick(): start activity b d/activity a: onpause() d/activity b: onresume()  ## user taps system key (but onbackpressed() not invoked. instead anr occurs) i/inputdispatcher(  557): anr in com.android.launcher d/activity b: onpause() 

here onbackpressed() method:

public void onbackpressed() {     intent intentstartroot = new intent().setcomponent(new componentname(this, activityhome.class));     intentstartroot.addflags(intent.flag_activity_reorder_to_front);     startactivity(intentstartroot); } 

this bug in android framework. tested on 12 devices today , noticed bug occurs reliably on nexus-type devices running these versions of android:

  • 4.4.4
  • 5.0.1
  • 5.0.2

interestingly, samsung devices running same versions of android not exhibit problem. android 5.1 , later seems better in see no more anrs in com.android.launcher; seeing anrs in com.google.android.googlequicksearchbox.

i worked around problem after noticing activity overriding onbackpressed() without invoking super.onbackpressed(). after added super.onbackpressed(), anrs went away. not full workaround because calling super.onbackpressed() finished activity, not want.

i hope helps someone.

see: using flag_activity_reorder_to_front switch among persistently running ui activities leads "no window focus" error

see: android-l issue: onbackpressed when using flag_activity_reorder_to_front launch previous activity & freezes app sometime

also, found bug entry on google's site seems related: https://code.google.com/p/android/issues/detail?id=91534


Comments