Search code examples
javaandroid-studioeventsandroid-activitymethods

Banner ad events (java)


I have a banner ad in my Activity. I have 4 @Overridable methods of banner ad in mainActivity.java.

What I want?

  1. I want to declare a method
  2. I want to put those 4 events to the my method

in one sentence:

Can I put @Overrides into the method?

private void allTogether(){

  @Override
public void onAdFailedToLoad(int errorCode) {
    // Code to be executed when an ad request fails.
}

@Override
public void onAdOpened() {
    // Code to be executed when an ad opens an overlay that
    // covers the screen.
}

@Override
public void onAdClicked() {
    // Code to be executed when the user clicks on an ad.
}

@Override
public void onAdLeftApplication() {
    // Code to be executed when the user has left the app.
}

@Override
public void onAdClosed() {
    // Code to be executed when the user is about to return
    // to the app after tapping on an ad.
}

How can I do that?


Solution

  • The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and then to modify behavior as needed. The overriding method has the same name, number and type of parameters, and return type as the method that it overrides. An overriding method can also return a subtype of the type returned by the overridden method. This subtype is called a covariant return type. If you attempt to call all the @Overridable methods from inside of one subclass method,

    What can you do with that? Overridable methods are for using them seperately. you can't call all of them with one method.