title: Logout dialog error: token android.os.BinderProxy@4276c0e8 is not valid; is your activity running
body: <p>I have a Login screen and upon success login, it finishes and shows AppActivity. Login screen is shown again if user logout from the app, finishing AppActivity. However, I have encountered an error as shown below when the login screen tries to show a dialog after user logout:</p>
  
  <pre><code>android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4276c0e8 is not valid; is your activity running?
  </code></pre>
  
  <p>LoginScreen is finished if user login into app successfully, showing AppActivity:</p>
  
  <pre><code>Intent intent = new Intent(LoginScreen.this, AppActivity.class);
  startActivity(intent);
  finish();
  </code></pre>
  
  <p>AppActivity is finished if user clicks logout button, showing LoginScreen:</p>
  
  <pre><code>Intent intent = new Intent(AppActivity.this, LoginScreen.class);
  intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  startActivity(intent);
  finish();
  </code></pre>