Interstitial ads are full-screen ads that cover the app interface. You display these ads at natural transition points in your app, such as between activities or during pauses in game levels. When an app shows an interstitial ad, your users can either tap on the ad and continue, or close the ad and return to the app. Read one of our case studies.
This guide explains how to integrate interstitial ads into an Android app.
Prerequisites
Always test with test ads
When building and testing your apps, make sure you use test ads rather than live, production ads. If you don't use test ads, Google can suspend your account.
The easiest way to load test ads is to use the dedicated test ad unit ID for Android interstitials:
ca-app-pub-3940256099942544/1033173712
This ad unit ID has been specially configured to return test ads for every request. You're free to use it in your own apps while coding, testing, and debugging. Make sure you replace it with your own ad unit ID before publishing your app.
For details on GMA Next-Gen SDK test ads, see Enable test ads.
Load an ad
The following example shows you how to load a single ad:
Kotlin
// Load ads after you initialize MobileAds. InterstitialAd.load( AdRequest.Builder(adUnitId).build(), object : AdLoadCallback<InterstitialAd> { override fun onAdLoaded(ad: InterstitialAd) { // Interstitial ad loaded. interstitialAd = ad } override fun onAdFailedToLoad(adError: LoadAdError) { // Interstitial ad failed to load. Log.e(TAG, "Interstitial ad failed to load: ${adError.message}") interstitialAd = null } }, )
Java
// Load ads after you initialize MobileAds. InterstitialAd.load( new AdRequest.Builder(adUnitId).build(), new AdLoadCallback<InterstitialAd>() { @Override public void onAdLoaded(@NonNull InterstitialAd ad) { // Interstitial ad loaded. interstitialAd = ad; } @Override public void onAdFailedToLoad(@NonNull LoadAdError adError) { // Interstitial ad failed to load. Log.e(TAG, "Interstitial ad failed to load: " + adError.getMessage()); interstitialAd = null; } });
When testing, use the test ad unit ID:
ca-app-pub-3940256099942544/1033173712.
Show the ad
To show an interstitial ad, use the show method.
Kotlin
private fun showAd(interstitialAd: InterstitialAd, activity: Activity) { // Show the ad. interstitialAd.show(activity) }
Java
private void showAd(InterstitialAd interstitialAd, Activity activity) { // Show the ad. interstitialAd.show(activity); }
Listen to ad events
Before showing the ad, listen to ad lifecycle events:
Kotlin
// Listen for ad events. val ad = interstitialAd if (ad == null) { Log.e(TAG, "Interstitial ad is not ready yet.") return } ad.adEventCallback = object : InterstitialAdEventCallback { override fun onAdShowedFullScreenContent() { // Interstitial ad did show. } override fun onAdDismissedFullScreenContent() { // Interstitial ad did dismiss. interstitialAd = null } override fun onAdFailedToShowFullScreenContent( fullScreenContentError: FullScreenContentError ) { // Interstitial ad failed to show. Log.e(TAG, "Interstitial ad failed to show: ${fullScreenContentError.message}") } override fun onAdImpression() { // Interstitial ad did record an impression. } override fun onAdClicked() { // Interstitial ad did record a click. } }
Java
// Listen for ad events. if (interstitialAd == null) { Log.e(TAG, "Interstitial ad is not ready yet."); return; } interstitialAd.setAdEventCallback( new InterstitialAdEventCallback() { @Override public void onAdShowedFullScreenContent() { // Interstitial ad did show. } @Override public void onAdDismissedFullScreenContent() { // Interstitial ad did dismiss. interstitialAd = null; } @Override public void onAdFailedToShowFullScreenContent( @NonNull FullScreenContentError fullScreenContentError) { // Interstitial ad failed to show. Log.e(TAG, "Interstitial ad failed to show: " + fullScreenContentError.getMessage()); } @Override public void onAdImpression() { // Interstitial ad did record an impression. } @Override public void onAdClicked() { // Interstitial ad did record a click. } });