2

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:

android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4276c0e8 is not valid; is your activity running?

LoginScreen is finished if user login into app successfully, showing AppActivity:

Intent intent = new Intent(LoginScreen.this, AppActivity.class);
startActivity(intent);
finish();

AppActivity is finished if user clicks logout button, showing LoginScreen:

Intent intent = new Intent(AppActivity.this, LoginScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
stackyyflow
  • 767
  • 3
  • 11
  • 30

1 Answers1

2

This can occur when you are showing the dialog for a context that no longer exists. A common case - if the 'show dialog' operation is after an asynchronous operation, and during that operation the original activity (that is to be the parent of your dialog) is destroyed.

This might be similar here. I hope it helps.

Community
  • 1
  • 1
eztephen
  • 38
  • 5