Interstitial Ads for Android

The myTarget SDK provides the ability to display an interstitial ads in your app. The myTarget SDK provides two ways to display interstitial ads: in a separate Activity or in a dialog box. We recommend that you display ads in a separate Activity, because displaying in a dialog box does not support all the features available for interstitial ads.

To display interstitial ads, you must add the MyTargetActivity to the application section of AndroidManifest.xml:

<activity android:name="com.my.target.ads.MyTargetActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

Initialization

To display interstitial ad in your app, create an instance of the InterstitialAd class. You must specify your slotId when creating an instance.
private InterstitialAd ad;
 
private void initAd()
{
    // Enabling debug mode
    // InterstitialAd.setDebugMode(true);
     
    // Create an instance of InterstitialAd
    ad = new InterstitialAd(YOUR_SLOT_ID, this);
}

Loading ads

To receive notifications (such as ad load succeeded, ad load failed, or ad clicked), you must create an object that implements the InterstitialAd.InterstitialAdListener interface and set it as an event listener. Then you can start loading ad.
private InterstitialAd ad;
 
private void initAd()
{
    // Create an instance of InterstitialAd
    ad = new InterstitialAd(YOUR_SLOT_ID, this);
    // Set the event listener
    interstitialAd.setListener(new InterstitialAd.InterstitialAdListener()
    {
        @Override
        public void onLoad(InterstitialAd ad)
        {
        }
 
        @Override
        public void onNoAd(String reason, InterstitialAd ad)
        {
        }
  
        @Override
        public void onClick(InterstitialAd ad)
        {
        }
  
        @Override
        public void onDisplay(InterstitialAd ad)
        {
        }
  
        @Override
        public void onDismiss(InterstitialAd ad)
        {
        }
 
 
        @Override
        public void onVideoCompleted(InterstitialAd ad)
        {
        }
    });
     
    // Start loading ad
    ad.load();
}

Displaying ads

After the ad has loaded successfully, you can start displaying interstitial ad.
@Override
public void onLoad(InterstitialAd ad)
{
    // Start displaying
    // in a separate Activity
    ad.show();
     
    // or in a dialog box
    //ad.showDialog();
}
Example of an interstitial banner

Mediation with other advertising SDKs

Mediation with the Admob SDK and Mopub SDK is supported for an interstitial ads. Mediation is configured using the corresponding interfaces.

AdMob

Mediation is configured at https://apps.admob.com/#monetize/

Specify the following values in the mediation settings:
Field
Value
Class Name
com.my.target.ads.mediation.MyTargetAdmobCustomEventInterstitial
Parameter
{"slotId":"<your slot Id>"}

Mopub mediation

Mediation is configured at http://www.mopub.com/

Specify the following values in the Network settings:
Field
Value
CUSTOM EVENT CLASS
com.mopub.mobileads.MyTargetMopubCustomEventInterstitial
CUSTOM EVENT CLASS DATA
{"slotId":"<your slot Id>"}
Was this article helpful?
Yes
No