Interstitial ads

Warning.

This is an archived version of the documentation. Actual documentation for all platforms can be found here.

An interstitial ad is a configurable ad that covers the entire screen and responds to clicks.

To enable advertising:

Creating an InterstitialAd

  1. Create an InterstitialAd class object. This object can only be created programmatically.

    mInterstitialAd = new InterstitialAd(this);
  2. Set the AdUnitId using the setAdUnitId method.

    mInterstitialAd.setAdUnitId(AdUnitId);

    AdUnitId is a unique identifier in R-M-XXXXXX-Y format, which is assigned in the Partner Interface.

  3. After creating and configuring an instance of the InterstitialAd class, you can set an InterstitialEventListener on the ad object for tracking events (opening or closing the ad, exiting the app, and loading the ad successfully or unsuccessfully).

Loading ads

Note.

Any call of the Mobile Ads SDK should be made from the main thread.

After creating and configuring an instance of the AdView class, load ads. To load an ad, use the loadAd method, which takes the AdRequest object as a parameter (or Builder, which optionally accepts ad targeting data).

Displaying ads

An interstitial ad is loaded in the background immediately after the loadAd call. To display an interstitial ad, you must call the show method.

We recommend checking whether the ad has actually loaded. To do this, call the isLoaded method.

Note.

You don't need to check this if the show method is called after the onAdLoaded callback has been triggered.

Example of working with interstitial ads

The following code demonstrates creating and configuring the InterstitialAd object, registering a listener, and loading and displaying the interstitial ad:

...
public class InterstitialExample extends Activity {
    ...
    private static final String AdUnitId = "YOUR_AdUnitId";
    private InterstitialAd mInterstitialAd;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        // Creating an InterstitialAd instance.
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(AdUnitId);

        // Creating an ad targeting object.
        final AdRequest adRequest = new AdRequest.Builder().build();

        // Registering a listener to track events in the ad.
        mInterstitialAd.setInterstitialAdEventListener(new InterstitialAdEventListener() {
            @Override
            public void onAdLoaded() {
                mInterstitialAd.show();
            }
            
            @Override
            public void onAdFailedToLoad(AdRequestError adRequestError) {
                ...
            }
            
            @Override
            public void onAdShown() {
                ...
            }
            
            @Override
            public void onAdDismissed() {
                ...
            }
            
            @Override
            public void onLeftApplication() {
                ...
            }
            
            @Override
            public void onReturnedToApplication() {
                ...
            }
        });

        // Loading ads.
        mInterstitialAd.loadAd(adRequest);
    }
}

If an ad is integrated this way, the ad unit appears after the app starts:

To see how the ad will be displayed in the app, use a demo AdUnitId:
YANDEX_AD_UNIT_ID = "demo-interstitial-yandex"
ADCOLONY_AD_UNIT_ID = "demo-interstitial-adcolony"
ADMOB_AD_UNIT_ID = "demo-interstitial-admob"
APPLOVIN_AD_UNIT_ID = "demo-interstitial-applovin"
CHARTBOOST_AD_UNIT_ID = "demo-interstitial-chartboost"
IRONSOURCE_AD_UNIT_ID = "demo-interstitial-ironsource"
MINTEGRAL_AD_UNIT_ID = "demo-interstitial-mintegral"
MYTARGET_AD_UNIT_ID = "demo-interstitial-mytarget"
PANGLE_AD_UNIT_ID = "demo-interstitial-pangle"
STARTAPP_AD_UNIT_ID = "demo-interstitial-startapp"
TAPJOY_AD_UNIT_ID = "demo-interstitial-tapjoy"
UNITYADS_AD_UNIT_ID = "demo-interstitial-unityads"
VUNGLE_AD_UNIT_ID = "demo-interstitial-vungle"