The method onBackPressed() of type FirstGroup must override a superclass method

浪尽此生 提交于 2019-12-12 04:00:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!