title: Using FLAG_ACTIVITY_REORDER_TO_FRONT to switch among persistently running UI activities leads to "no window focus" error
body: <p>My objective is to keep two UI activities alive and to switch back and forth between them at will without having to kill/restart either of them.  But there is a serious side effect of using <strong>FLAG_ACTIVITY_REORDER_TO_FRONT</strong> to do this: a loss of window focus when I resume a previous activity (that is currently running in the background).</p>
  
  <p>I proved this issue by spending 5 minutes creating a simple application with two "Hello World" activities.</p>
  
  <ol>
  <li>The app starts with Activity A, which simply shows a button (nothing else) called "Launch B".</li>
  <li>Press this button -- this executes <code>startActivity(FLAG_ACTIVITY_REORDER_TO_FRONT, ActivityB.class).</code></li>
  <li>Activity B becomes active, which shows simply shows a button called "Launch A".</li>
  <li>Press this button -- this executes <code>startActivity(FLAG_ACTIVITY_REORDER_TO_FRONT, ActivityA.class).</code></li>
  <li>Activity A's <code>onResume()</code> is called as expected and everything looks fine (I can see Activity A content again).</li>
  <li>Press the device's Back key and this set of errors will occur 100% of the time:</li>
  </ol>
  
  <blockquote>
    <p>E/ActivityManager(  513): Reason: 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.)</p>
    
    <p>I/WindowState(  513): WIN DEATH: Window{5294687c u0
    com.android.launcher/com.android.launcher2.Launcher}</p>
    
    <p>W/ViewRootImpl( 8066): <strong>Dropping event due to no window focus</strong>:
    KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=0,
    metaState=0, flags=0xc8, repeatCount=1, eventTime=14965546,
    downTime=14965045, deviceId=-1, source=0x101 }</p>
  </blockquote>
  
  <p>(The practical result of the window death is essentially a "crash" from the user's point of view -- Android throws the user out of the app back to the Home screen, though technically the application remains running in the background.)</p>
  
  <p>I debugged this and found that the reason Activity A is visible but doesn't have focus is because activity A's <strong>onWindowFocusChanged() is NOT called</strong> like it normally does (even though onResume() is called).  <strong>This has something to do with the fact with Activity B is still active in the background</strong> (even though clearly B has lost focus -- onWindowFocusChanged(false) was called for B, as well as onStop()).  <strong>I know this because after step 4 above if I immediately call finish() on Activity B, Activity A's onWindowFocusChanged(true) WILL be called and everything is normal.</strong>  The fact that Activity B is still active but not focused somehow interferes with Activity A regaining focus like it should.  Is this an Android bug or am I missing something?</p>
  
  <p>Note that if Activity A had multiple views in it and I were to touch one of those views after step 6 above, I would get the same "Dropping event due to no window focus" error, though not 100% of the time for some reason. </p>