Migrate interstitial ads

This page covers the differences in loading and showing an interstitial ad between the current and Google Mobile Ads SDK (beta).

Load an ad

The following examples load an interstitial ad:

Current

Kotlin

InterstitialAd.load(
  this@InterstitialActivity,
  "AD_UNIT_ID",
  AdRequest.Builder().build(),
  object : InterstitialAdLoadCallback() {
    override fun onAdLoaded(ad: InterstitialAd) {
      // Called when an ad has loaded.
      ad.fullScreenContentCallback =
        object : FullScreenContentCallback() {
        }
      interstitialAd = ad
    }

    override fun onAdFailedToLoad(loadAdError: LoadAdError) {
      // Called when ad fails to load.
    }
  }
)

Java

InterstitialAd.load(
  this,
  "AD_UNIT_ID",
  new AdRequest.Builder().build(),
  new InterstitialAdLoadCallback() {
    @Override
    public void onAdLoaded(@NonNull InterstitialAd ad) {
      // Called when an ad has loaded.
      ad.setFullScreenContentCallback(new FullScreenContentCallback() {});
      interstitialAd = ad;
    }

    @Override
    public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
      // Called when ad fails to load.
    }
  }
);
Google Mobile Ads SDK (beta)

Kotlin

InterstitialAd.load(
  AdRequest.Builder("AD_UNIT_ID").build(),
  object : AdLoadCallback<InterstitialAd> {
    override fun onAdLoaded(ad: InterstitialAd) {
      // Called when an ad has loaded.
      ad.adEventCallback =
        object : InterstitialAdEventCallback {
        }
      interstitialAd = ad
    }

    override fun onAdFailedToLoad(loadAdError: LoadAdError) {
      // Called when ad fails to load.
    }
  }
)

Java

InterstitialAd.load(
    new AdRequest.Builder("AD_UNIT_ID").build(),
    new AdLoadCallback<InterstitialAd>() {
      @Override
      public void onAdLoaded(@NonNull InterstitialAd ad) {
        // Called when an ad has loaded.
        ad.setAdEventCallback(new InterstitialAdEventCallback() {});
        interstitialAd = ad;
      }

      @Override
      public void onAdFailedToLoad(@NonNull LoadAdError adError) {
        // Called when ad fails to load.
      }
    });

Show an ad

The following examples show an interstitial ad:

Current

Kotlin

interstitialAd?.show(this@InterstitialActivity)

Java

interstitialAd.show(this);
Google Mobile Ads SDK (beta)

Kotlin

interstitialAd?.show(this@InterstitialActivity)

Java

interstitialAd.show(this);