I was trying to override the back button functionality where I wanted to call the default functionality in case a boolean is set false
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean temp = false;
if (event.KEYCODE_BACK == keyCode) {
System.out.println("Back press开发者_StackOverflow中文版ed");
if (isTrue) {
//Do something
return true;
}
else return false;
}
return false;
}
Now this doesn't exactly work how the documentation states. the //Do Something
part is executed well, but when isTrue
is false
i want the default back functionality which is not happening. Im using SDK 1.5
Now,
How do I fix this?
Is this issue fixed in later SDK updates? If not can someone raise a bug for the same?
If you want the default behavior, chain to the superclass:
return(super.onKeyDown(keyCode, event));
The bug is in your code. Also, for Android 1.6 and newer, you are better served overriding the dedicated
onBackPressed()
method (where, again, if you want the default behavior, chain to the superclass).
精彩评论