Interstitial ads

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

To enable advertising:

Creating InterstitialAd

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

    mInterstitialAd = new InterstitialAd(this);
  2. Set the Block ID using the setBlockId method.

    mInterstitialAd.setBlockId(BLOCK_ID);
    Block ID is a unique identifier in the adf-XXXXXX/YYYYYY format, which is assigned in the Partner interface.
    Attention.

    In the mobile mediation interface, the Block ID is called the location ID.

  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

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 onInterstitialLoaded callback, which indicates that loading has finished.

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 BLOCK_ID = "YOUR_BLOCK_ID";
    private InterstitialAd mInterstitialAd;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        // Creating an InterstitialAd instance.
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setBlockId(BLOCK_ID);

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

        // Registering a listener to track events that occur in the ad.
        mInterstitialAd.setInterstitialEventListener(new InterstitialEventListener.SimpleInterstitialEventListener() {
            @Override
            public void onInterstitialLoaded() {
                mInterstitialAd.show();
            }
        });

        // Loading the ad.
        mInterstitialAd.loadAd(adRequest);
    }
}

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