views:

209

answers:

1

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?

+2  A: 

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


Rahul
Adding super.onBackPressed() won't help if the method isn't defined in the superclass. You *could* remove the @Override annotation, in which case this would build against 1.5, but the onBackPressed method wouldn't be called.
Adrian
Yes, Adrian is right, how can I do it in API level 3? Thanks
Burjua
check my updated post...
Rahul
Ok, thanks, I will try it
Burjua