Interstitial ads
This is an archived version of the documentation. Actual documentation for all platforms can be found here.
An interstitial ad is a configurable ad that covers the entire screen and responds to clicks.
To enable advertising:
Creating an InterstitialAd
Create an InterstitialAd class object. This object can only be created programmatically.
mInterstitialAd = new InterstitialAd(this);
Set the AdUnitId using the setAdUnitId method.
mInterstitialAd.setAdUnitId(AdUnitId);
AdUnitId
is a unique identifier in R-M-XXXXXX-Y format, which is assigned in the Partner Interface.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
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.
You don't need to check this if the show method is called after the onAdLoaded callback has been triggered.
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 AdUnitId = "YOUR_AdUnitId";
private InterstitialAd mInterstitialAd;
@Override
public void onCreate(Bundle savedInstanceState) {
...
// Creating an InterstitialAd instance.
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(AdUnitId);
// Creating an ad targeting object.
final AdRequest adRequest = new AdRequest.Builder().build();
// Registering a listener to track events in the ad.
mInterstitialAd.setInterstitialAdEventListener(new InterstitialAdEventListener() {
@Override
public void onAdLoaded() {
mInterstitialAd.show();
}
@Override
public void onAdFailedToLoad(AdRequestError adRequestError) {
...
}
@Override
public void onAdShown() {
...
}
@Override
public void onAdDismissed() {
...
}
@Override
public void onLeftApplication() {
...
}
@Override
public void onReturnedToApplication() {
...
}
});
// Loading ads.
mInterstitialAd.loadAd(adRequest);
}
}
If an ad is integrated this way, the ad unit appears after the app starts:
YANDEX_AD_UNIT_ID = "demo-interstitial-yandex"
ADCOLONY_AD_UNIT_ID = "demo-interstitial-adcolony"
ADMOB_AD_UNIT_ID = "demo-interstitial-admob"
APPLOVIN_AD_UNIT_ID = "demo-interstitial-applovin"
CHARTBOOST_AD_UNIT_ID = "demo-interstitial-chartboost"
IRONSOURCE_AD_UNIT_ID = "demo-interstitial-ironsource"
MINTEGRAL_AD_UNIT_ID = "demo-interstitial-mintegral"
MYTARGET_AD_UNIT_ID = "demo-interstitial-mytarget"
PANGLE_AD_UNIT_ID = "demo-interstitial-pangle"
STARTAPP_AD_UNIT_ID = "demo-interstitial-startapp"
TAPJOY_AD_UNIT_ID = "demo-interstitial-tapjoy"
UNITYADS_AD_UNIT_ID = "demo-interstitial-unityads"
VUNGLE_AD_UNIT_ID = "demo-interstitial-vungle"