How to detect when the user dismisses a interstitial in Admob?

Viewed 3863

I recently moved my ads to the newer version (now uses com.google.android.gms.ads), but I realised that I am now missing something quite important. I used to be able to detect when the user dismissed their interstitial with OnDismissScreen, but now it looks like this is no longer an option:

I used to do:

@Override
public void onDismissScreen(Ad arg0) {
  interstitial = new InterstitialAd(this, "appid");
  interstitial.loadAd(new AdRequest());
  interstitial.setAdListener(this);
}

Is there any sort of equivalent in the newer version of Admob?

Thanks!

2 Answers

With AdMob v20.0.0 the AdListener has been deprecated for the full screen ad format.

You should now attach a FullScreenContentCallback and override onAdDismissedFullScreenContent() on the InstertitialAd instance passed by the InstertitialAdLoadCallback#onAdLoaded attached when calling InterstitialAd#load.

In kotlin it should look somenthing like this:

    InterstitialAd.load(context, unitId, adRequest, object : InterstitialAdLoadCallback() {
        override fun onAdFailedToLoad(adError: LoadAdError) {
          // TODO handle error!
        }

        override fun onAdLoaded(interstitialAd: InterstitialAd) {
          interstitialAd.fullScreenContentCallback = object: FullScreenContentCallback() {
              override fun onAdDismissedFullScreenContent() {
                  super.onAdDismissedFullScreenContent()
                  // TODO Handle here the interstitial dismissed. 
              }
          }
        }
      })

If you need more information here you can find the official guide made to migrate to v20.0.0

Related