Enabling 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 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

After creating and configuring an instance of the AdView class, you need to load the ad. 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) {
        ...
        // Create an instance of InterstitialAd.
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setBlockId(BLOCK_ID);

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

        // Register the listener for tracking events in the ad.
        mInterstitialAd.setInterstitialEventListener(new InterstitialEventListener.SimpleInterstitialEventListener() {
            @Override
            public void onInterstitialLoaded() {
                mInterstitialAd.show();
            }
        });

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

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

To see how the ad will be displayed in the app, use a demo Block ID:
  • R-M-DEMO-240x400-context
  • R-M-DEMO-320x480
  • R-M-DEMO-400x240-context
  • R-M-DEMO-480x320