Interstitial ads

This section provides details and examples of how to configure, load, and display an interstitial ad. You can display the ad when it loads, or on some other specific event; for example, when the user clicks a button.

Set up and load an interstitial ad

Before you can display an ad on your app or site, you first need to configure the ad, and then pass the ad placement ID to the load method. For example:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // set configuration to production
        SAInterstitialAd.setConfigurationProduction();

        // display test ads. Pre-defined test placements are
        // retrieved from the ads server.
        SAInterstitialAd.enableTestMode();

        // lock orientation to portrait or landscape
        SAInterstitialAd.setOrientationPortrait();

        // enable or disable the Android back button
        SAInterstitialAd.enableBackButton();

        // enable or disable a close button that displays without a delay. Use instead of enableCloseButton.
        // WARNING: this will allow users to close the ad before the viewable tracking event is fired
        // and should only be used if you explicitly want this behavior over consistent tracking.
        SAInterstitialAd.enableCloseButtonNoDelay();

        // start loading ad data for a placement
        SAInterstitialAd.load(30473, MainActivity.this);
    }
}
class MainActivity : Activity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // set configuration to production
        SAInterstitialAd.setConfigurationProduction()

        // display test ads. Pre-defined test placements are
        // retrieved from the ads server.
        SAInterstitialAd.enableTestMode()

        // lock orientation to portrait or landscape
        SAInterstitialAd.setOrientationPortrait()

        // enable or disable the Android back button
        SAInterstitialAd.enableBackButton()

        // enable or disable a close button that displays without a delay. Use instead of enableCloseButton.
        // WARNING: this will allow users to close the ad before the viewable tracking event is fired
        // and should only be used if you explicitly want this behavior over consistent tracking.
        SAInterstitialAd.enableCloseButtonNoDelay()

        // start loading ad data for a placement
        SAInterstitialAd.load(30473, this)
    }
}
Parameter Default value Configure using
Configuration Production setConfigurationProduction()
Test mode Disabled enableTestMode(), disableTestMode()
Orientation Any setOrientationPortrait(), setOrientationLandscape(), setOrientationAny()
Close button Enabled enableCloseButton(), disableCloseButton(), enableCloseButtonNoDelay(), enableCloseButtonWithDelay(5.0)
Back button Enabled enableBackButton(), disableBackButton()

Aditional load parameters

You can also send additional options during the load() call as well as an optional OpenRTB partner ID. Both parameters are optional.

Map<String, Object> options = new HashMap<>();
options.put("key", "value");
String openRTBPartnerId = "1234";
SAInterstitialAd.load(30471, openRTBPartnerId, options);
val options = mapOf("key", "value")
val openRTBPartnerId = "1234"
SAInterstitialAd.load(30471, openRTBPartnerId, options)

Close Button Defaults

The close button is displayed by default on interstitial ads unless settings are changed to disable it. The default delay before showing the close button is 1 second after the ad is loaded. This delay time cannot currently be configured to a different amount of time.

Display the interstitial ad

To display the ad, call play, using either the adLoaded callback or the hasAdAvailable method.

  • Use the adLoaded callback to display the ad as soon as it is loaded. Add the callback before you call the load method. For example:
// use the adLoaded callback to trigger playing the ad
SAInterstitialAd.setListener(new SAInterface () {
    @Override
    public void onEvent(int placementId, SAEvent event) {
        // when the ad loads, play it directly
        if (event == SAEvent.adLoaded) {
            SAInterstitialAd.play(placementId, MainActivity.this);
        }
    }
});

// start loading ad data for a placement
SAInterstitialAd.load(30473, MainActivity.this);
// use the adLoaded callback to trigger playing the ad
SAInterstitialAd.setListener { placementId, event ->   
    // when the ad loads, play it directly
    if (event == SAEvent.adLoaded) {
        SAInterstitialAd.play(placementId, this@MainActivity);
    }
}

// start loading ad data for a placement
SAInterstitialAd.load(30473, this)
  • Use the hasAdAvailable method to play the ad on some other event, such as when the user clicks a button in the app. For example:
@Override
protected void onClick(View view) {

    // check if ad is loaded
    if (SAInterstitialAd.hasAdAvailable(30473)) {

        // display the ad
        SAInterstitialAd.play(30473, MainActivity.this);
    }
}
override fun onClick(view: View) {
    // check if ad is loaded
    if (SAInterstitialAd.hasAdAvailable(30473)) {
        // display the ad
        SAInterstitialAd.play(30473, this)
    }
}