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();