Interstitial ads are full-screen ads that cover the interface of their host app. They're typically displayed at natural transition points in the flow of an app, such as between activities or during the pause between levels in a game. When an app shows an interstitial ad, the user has the choice to either tap on the ad and continue to its destination or close it and return to the app. The direct call to action and larger size combine to make interstitial ads a particularly effective form of mobile advertisement.
Because of their larger size, interstitial ads require more bandwidth on average than traditional banners. To accommodate this, the recommended approach is to have apps load them in advance of when they will be displayed. This helps ensure that an ad is ready to go when the time comes to display one.
This guide explains how to integrate interstitial ads into your Android apps using the Google Mobile Ads SDK. It presents a simple activity class that uses SDK methods to preload and then display a test interstitial ad.
The ad unit and samples that we provide return test ads. Test ads are always available, even if your account is suspended or disabled. For more information, review the AdMob policies and learn more about invalid activity.
It is against AdMob policy to click on your own live ads. During development and testing, use only test ads. If you do need to render live ads before launch, avoid clicking on them. If you click on live ads, your AdMob account may be suspended.
Helpful resources
If you haven't already completed it, consider running through the Get Started in Android Studio guide.
Prerequisites
The sample code in this guide is from a project that has already included the Google Mobile Ads SDK. In order to use the SDK in your own app, you'll need to either configure Gradle to reference Google Play services in Android Studio or perform the following steps in Eclipse:
- Download Google Play services
- Include and reference the Google Play services library project
- Modify the manifest file
Add interstitial ads to an activity
The recommended approach for an interstitial ad is to load it in advance and then show it later when there's a natural pause in the flow of your app. Let's say, for example, that we have a simple game that runs for a while, ends, and then presents the user with a button to start again. Here's a code snippet that shows how to preload and display an interstitial ad before the user begins a new game:
... public class MainActivity extends ActionBarActivity { InterstitialAd mInterstitialAd; Button mNewGameButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mNewGameButton = (Button) findViewById(R.id.newgame_button); mInterstitialAd = new InterstitialAd(this); mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdClosed() { requestNewInterstitial(); beginPlayingGame(); } }); requestNewInterstitial(); mNewGameButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mInterstitialAd.isLoaded()) { mInterstitialAd.show(); } else { beginPlayingGame(); } } }); beginPlayingGame(); } private void requestNewInterstitial() { AdRequest adRequest = new AdRequest.Builder() .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID") .build(); mInterstitialAd.loadAd(adRequest); } private void beginPlayingGame() { // Play for a while, then display the New Game Button } } ...
Including the introduction of a new member variable, mInterstitialAd
,
there are four places in the activity at which the code has changed.
Let's take a look at them individually.
Instantiate the InterstitialAd object
Here, the member variable mInterstitialAd
is constructed and given an ad unit
ID. While banner ads are typically defined in an XML layout file,
interstitial ads are not. They're created and configured in an app's Java code.
A single
InterstitialAd
object can be used to request and display multiple interstitial ads over the
course of an activity's lifespan, so you only need to construct it once.
...
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
requestNewInterstitial();
...
Display the interstitial ad
Here the new code checks to see if an interstitial ad has been loaded, and if so, displays it:
... mNewGameButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mInterstitialAd.isLoaded()) { mInterstitialAd.show(); } else { beginPlayingGame(); } } }); ...
If no ad is ready, the app goes straight into the next game.
Create the AdListener
Here, we're setting up an
AdListener
that includes a handler for the
onAdClosed()
event, which is invoked when an interstitial ad is closed. The code above calls the
requestNewInterstitial()
method to begin downloading a new ad, and starts a new
game:
...
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
beginPlayingGame();
}
});
...
requestNewInterstitial()
...
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mInterstitialAd.loadAd(adRequest);
}
...
Here, an AdRequest.Builder
object is used to create a simple request that is
then passed into the
InterstitialAd
object's
loadAd()
method, beginning the request process.
Note the use of the
addTestDevice()
method during the creation of the request.
It is against AdMob policy to click on your own live ads. During development and
testing, use only test ads. If you do need to render live ads before launch,
avoid clicking on them. If you click on live ads, your AdMob account may be
suspended.
You must have the hashed ID of the device you want to add. In the above example,
it is the ID for an emulator: AdRequest.DEVICE_ID_EMULATOR
. Use
test ads to avoid generating invalid
clicks.
The result
Here's what the app looks like when an interstitial ad is shown:
When the interstitial ad is displayed, it covers the entire screen. The user can close the ad by tapping the "X" in the upper-left (or sometimes upper-right) corner. Or, the user can go to the ad's destination URL by tapping elsewhere (generally anywhere, but sometimes only certain areas are active).
Some best practices
- Consider whether interstitial ads are the right type of ad for your app.
- Interstitial ads work best in apps with natural transition points. The conclusion of a task within an app, like sharing an image or completing a game level, creates such a point. Because the user is expecting a break in the action, it's easy to present an interstitial ad without disrupting their experience. Make sure you consider at which points in your app's workflow you'll display interstitial ads and how the user is likely to respond.
- Remember to pause the action when displaying an interstitial ad.
- There are a number of different types of interstitial ads: text, image,
video, and more.
It's important to make sure that when your app displays
an interstitial ad, it also suspends its use of some resources to allow
the ad to take advantage of them. For example, when you make the call to display
an interstitial ad, be sure to pause any audio output being produced by your app.
You can resume playing sounds in the
onAdClosed()
event handler, which will be invoked when the user has finished interacting with the ad. In addition, consider temporarily halting any intense computation tasks (such as a game loop) while the ad is being displayed. This will make sure the user doesn't experience slow or unresponsive graphics or stuttered video. - Allow for adequate loading time.
- Just as it's important to make sure you display interstitial ads at an
appropriate time, it's also important to make sure the user doesn't have to
wait for them to load. Loading the ad in advance by calling
loadAd()
before you intend to callshow()
can ensure that your app has a fully loaded interstitial ad at the ready when the time comes to display one. - Don't flood the user with ads.
- While increasing the frequency of interstitial ads in your app might seem like a great way to increase revenue, it can also degrade the user experience and lower clickthrough rates. Make sure that users aren't so frequently interrupted that they're no longer able to enjoy the use of your app.
Further reading
- Interstitial ad guidance gives best practices for integrating interstitial ads.
- Disallowed interstitial ad implementations describes practices to avoid.
- Invalid activity explains when a click or impression is considered false.
- Behavioral policies outlines AdMob's extensions to the AdSense program policies and further discusses disallowed activities.
You can also download our example app and see interstitial ads in action:
FAQ
- When I try to load a second interstitial ad, I see "An interstitial is already loading. Aborting." in my logs. What happened?
- This warning appears when an app attempts to load a new interstitial ad before
it's finished displaying the previous one. Make sure you're calling
loadAd()
in the right place (we recommend theonAdClosed()
method of an ad listener). - When I call
loadAd()
on an InterstitialAd object, I'm getting the message "Cannot present interstitial. It is not ready." What's going on? - This error means the interstitial ad was not successfully fetched. To prevent
this warning from happening, use the
isLoaded()
method to check if the interstitial ad is ready to present. - I'm not getting any ads back, and my log says "Request Error: No ads to show."
- When creating an ad unit, make sure to specify "Interstitial" for the ad type.
InterstitialAd
objects only accept ad units that are configured to serve interstitial ads.