Ad callbacks

Before you start to set up your ads, it is important to understand the ad callbacks available in the AwesomeAds SDK.

Banner ads, interstitial ads, and video ads all send a number of callbacks to notify you of important lifecycle events, enabling you to perform specific actions when those events occur.

For example, you can use the adLoaded callback to play an ad as soon as it is loaded. Alternatively, you might wish to run some other custom code when you get the adLoaded callback.

Callbacks versus methods

In some situations, you may need to choose between using a callback or a method. In general, it is recommended that you use a callback when you need to respond immediately to an event.

For example, to play an ad, you can use either the adLoaded callback or the HasAdAvailable method.

  • If you want to play the ad as soon as it is loaded, it is recommended that you use the adLoaded callback.
  • If you want to load the ad at one point (for example, when the game starts) but not play it until some later stage, use the HasAdAvailable method.

For more information, see banner ad, interstitial ad, video ad.

Also see the examples:

AwesomeAds ad callbacks

These are all the ad callbacks available in the AwesomeAds SDK:

SAVideoAd.setListener (new SAInterface() {
    @Override
    public void onEvent(int placementId, SAEvent event) {
        switch (event) {
            case adLoaded:
                // called when an ad has finished loading
                break;
            case adEmpty:
                // called when the request was successful but the server returned no ad
                break;
            case adFailedToLoad:
                // called when an ad could not be loaded
                break;
            case adAlreadyLoaded:
                // called when the ad was previously loaded for the given creativeId
                break;
            case adShown:
                // called when an ad is first shown
                break;
            case adFailedToShow:
                // called when an ad fails to show
                break;
            case adClicked:
                // called when an ad is clicked
                break;
            case adEnded:
                // called when a video ad has ended playing (but hasn't yet closed)
                break;
            case adClosed:
                // called when a fullscreen ad is closed
                break;
            case adPaused:
                // called when the video ad is paused
                break;
            case adPlaying:
                // called when the video ad starts or resumes playing
                break;
            case webSDKReady:
                // called when the webSDK is ready (interactive video only)
                break;
        }
    }
});
SAVideoAd.setListener { placementId, event ->
    when (event) {
        when (event) {
                SAEvent.adLoaded -> { /* called when an ad has finished loading */ }
                SAEvent.adEmpty -> { /* called when the request was successful but the server returned no ad */ }
                SAEvent.adFailedToLoad -> { /* called when an ad could not be loaded */ }
                SAEvent.adAlreadyLoaded -> { /* called when the ad was previously loaded for the given creativeId */ }
                SAEvent.adShown -> { /* called when an ad is first shown */ }
                SAEvent.adFailedToShow -> { /* called when an ad fails to show */ }
                SAEvent.adClicked -> { /* called when an ad is clicked */ }
                SAEvent.adEnded -> { /* called when a video ad has ended playing (but hasn't yet closed) */ }
                SAEvent.adClosed -> { /* called when a fullscreen ad is closed */ }
                SAEvent.adPaused -> { /* called when the video ad is paused */ }
                SAEvent.adPlaying -> { /* called when the video ad starts or resumes playing */ }
                SAEvent.webSDKReady -> { /* called when the webSDK is ready (interactive video only) */ }
            }
    }
};