BadTokenException - BACK button
I know this topic was asked trillions of times throughout the web, but there is no one place answering it.
in my application, I have a welcome screen. when I run the program end-to-end everything is just fine - open/close activities and show dialogs of all sorts.
but, when I reach the welcome screen and from there pressing the BACK button - everything becomes messy: 1) the dialog i want to show cause BadTokenException (i'm usingthis
and not getApplicationContext()
).
2) I tried use try/catch to catch the exception - and it really passed the showDialog
line. but then, in the 2nd. run, when reaching a showDialog
expression, it throws IllegalStateException: View.com.android.internal.policy.impl.PhoneWindow$DecorView@44a59830 has already been added to the window manager
.
moreover, I understand that pressing HOME causes the onPause in the activity, while BACK causes onDestroy, but what goes开发者_如何学JAVA wrong ??
i'm trying to fix that issue for more than a week, but with no success. any ideas ?
I didn't get you complete, But i think you need to do some stuff when you back button is pressed. So you can override you back button in you welcome screen activity or any other activity and add you code there
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// add you code here
return true;
}
return super.onKeyDown(keyCode, event);
}
精彩评论