问题
I'm trying to override the onBackPressed() method of the ActivityGroup class:
public class MyClass extends ActivityGroup {
@Override
public void onBackPressed() {
// do something
return;
}
but I'm getting the error The method onBackPressed() of type MyClass must override a superclass method.
I'm relatively new to Java, I've seen here that people do it and it works for them
Why I'm getting this error?
I'm writing an app for android 1.5, could the problem be here?
回答1:
Edit
You need to override the back button like this
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
Log.d(this.getClass().getName(), "back button pressed");
}
return super.onKeyDown(keyCode, event);
}
Yes u r correct onBackPressed() method has been introduced only in API Level 5 which means you can use it only from 2.0 SDK
来源:https://stackoverflow.com/questions/3658301/the-method-onbackpressed-of-type-firstgroup-must-override-a-superclass-method