onBackPressed() override error

2.1k Views Asked by At

i want to implement Appbrain interstitial ad on my live wallpaper settings,
i followed steps given on - http://www.appbrain.com/info/sdk-docs/interstitial.html

@Override
public void onBackPressed() {
    AppBrain.getAds().maybeShowInterstitial(this);
    finish();
} 

Note: eclipse red underline on onBackPressed()

The eclipse is giving error:

The method onBackPressed() of type SBLiveWallpaper must override or implement a supertype method

One quick fix is: Remove @override annotation

What is the solution?

Update: Here is the screenshot: http://prntscr.com/558my0

4

There are 4 best solutions below

0
On

All that @Override annotation is doing is letting you know that the method is supposed to override a super class implementation of that method. If you are getting an error, that means it is not overriding anything and it is just a normal method. Check that you are implementing the correct interfaces or extending the correct super class that contains the onBackPressed method.

0
On

As eclipse itself provide you hint to catch solution of your exception

The method onBackPressed() of type SBLiveWallpaper must override or implement a supertype method

your class SBLiveWallpaper must extend an Activity class which has onBackPressed() method so you can override that method only if you extend Activity class directly or indirectly.

Like :

public SBLiveWallpaper extends Activity {

    @Override
    public void onBackPressed() {
        AppBrain.getAds().maybeShowInterstitial(this);
        finish();
    }

}
4
On

Add super.onBAckPress(); in place of finish().

1
On

Call super.onBackPressed(); do not remove @override.

@Override
public void onBackPressed() {
super.onBackPressed();
    AppBrain.getAds().maybeShowInterstitial(this);
    finish();
} 

As mentioned on the link you have provided.