Interstitial Ads

We support both static and video interstitial ads. Follow the instructions below to set up interstitial ads.

Set up Interstitial Ad

  1. From the left navigation, select Inventory Inventory Settings.
  2. Search for the app or website you would like to create a placement for and click + Add a placement.
  3. Click Select Ad Unit and select Interstitial.
  4. Click Add a placement to start setting up your Interstitial settings. After you create the Interstitial placement, you can see the placement ID.

     

Add Interstitial Ad to your App

Creating Interstitial Ad

To create an interstitial ad, create an instance of an InMobiInterstitial:

Java

InMobiInterstitial interstitialAd = new InMobiInterstitial(InterstitialAdsActivity.this, 1471550843414L, 
mInterstitialAdEventListener);

Kotlin

val interstitialAd = InMobiInterstitial(this@InterstitialAdsActivity, 1471550843414L, mInterstitialAdEventListener )

Here, mInterstitialAdEventListener is an implementation of the InterstitialAdEventListener Abstract class. It is mandatory to supply an implementation of this abstract class to create an interstitial ad.

Warning

  • The InMobiInterstitial class is not thread-safe. An interstitial instance must be created on the UI thread.
  • Similarly, all methods on this instance must be called on the UI thread. Not doing so will lead to unpredictable behavior and may affect your ability to monetize with InMobi.
  • Creating an InMobi Interstitial object without SDK Initialization will throw an exception.

InterstitialAdEventListener abstract class allows you to listen to key lifecycle events for an interstitial ad. You should listen to these events to ensure that your application correctly handles the various lifecycle transitions.

Java

/**
* Listener for receiving notifications during the lifecycle of an interstitial.
*/
public abstract class InterstitialAdEventListener {
    /**  
     * Called to indicate that an ad was loaded and it can now be shown. This will always be called  
     * after the {@link ##onAdFetchSuccessful(InMobiInterstitial, AdMetaInfo)} callback.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which was loaded  
     * @param info Represents the ad meta information  
     */ 
    public void onAdLoadSucceeded(@NonNull InMobiInterstitial ad, @NonNull AdMetaInfo info) {} 
    /**  
     * Callback to signal that a request to fetch an ad (by calling  
     * {@link InMobiInterstitial##load()} failed. The status code indicating the reason for failure  
     * is available as a parameter. You should call {@link InMobiInterstitial##load()} again to  
     * request a fresh ad.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which failed to load  
     * @param status Represents the {@link InMobiAdRequestStatus} status containing error reason  
     */ 
    public void onAdLoadFailed(@NonNull InMobiInterstitial ad, @NonNull InMobiAdRequestStatus status) {} 
    /**  
     * Called to indicate that an ad is available in response to a request for an ad (by calling  
     * {@link InMobiInterstitial##load()}. Note: This does not  
     * indicate that the ad can be shown yet. Your code should show an ad after the  
     * {@link ##onAdLoadSucceeded(InMobiInterstitial)} method is called. Alternately, if you do not  
     * want to handle this event, you must test if the ad is ready to be shown by checking the  
     * result of calling the {@link InMobiInterstitial##isReady()} method.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad for which ad content was received  
     * @param info Represents the ad meta information  
     */ 
    public void onAdFetchSuccessful(@NonNull InMobiInterstitial ad, @NonNull AdMetaInfo info) {} 
    /**  
     * Called to indicate that an ad interaction was observed.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad on which user clicked  
     * @param params Represents the click parameters  
     */ 
    public void onAdClicked(@NonNull InMobiInterstitial ad, Map < Object, Object > params) {} 
    /**  
     * Called to indicate that the ad will be launching a fullscreen overlay.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which will display  
     */ 
    public void onAdWillDisplay(@NonNull InMobiInterstitial ad) {} 
    /**  
     * Called to indicate that the fullscreen overlay is now the topmost screen.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which is displayed  
     * @param info Represents the ad meta information  
     */ 
    public void onAdDisplayed(@NonNull InMobiInterstitial ad, @NonNull AdMetaInfo info) {} 
    /**  
     * Called to indicate that a request to show an ad (by calling {@link InMobiInterstitial##show()}  
     * failed. You should call {@link InMobiInterstitial##load()} to request for a fresh ad.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which failed to show  
     */ 
    public void onAdDisplayFailed(@NonNull InMobiInterstitial ad) {} 
    /**  
     * Called to indicate that the fullscreen overlay opened by the ad was closed.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which was dismissed  
     */ 
    public void onAdDismissed(@NonNull InMobiInterstitial ad) {} 
    /**  
     * Called to indicate that the user may leave the application on account of interacting with the ad.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad  
     */ 
    public void onUserLeftApplication(@NonNull InMobiInterstitial ad) {} 
    /**  
     * Called to indicate that rewards have been unlocked.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad for which rewards was unlocked  
     * @param rewards Represents the rewards unlocked  
     */ 
    public void onRewardsUnlocked(@NonNull InMobiInterstitial ad, Map < Object, Object > rewards) {} 
    /** 
     * Called to notify that inmobi has logged an impression for the ad 
     * @param ad     Represents the ad which was impressed 
     */ 
    public void onAdImpression(@NonNull InMobiInterstitial ad) { 
    } 
}

Kotlin

/**
* Listener for receiving notifications during the lifecycle of an interstitial.
*/
abstract class InterstitialAdEventListener : AdEventListener<inmobiinterstitial>() {
/**
    * Called to notify that an ad preload has failed.  
    *  
    ***Note** This notification is given only when you use `preload()` in  
    * [InMobiInterstitial.preloadManager]  
    *  
    * @param ad     Represents the [InMobiInterstitial] ad which was preloaded  
    * @param status Represents the [InMobiAdRequestStatus] status containing error reason  
    */  
open fun onAdFetchFailed(ad: InMobiInterstitial, status: InMobiAdRequestStatus) {}
/**
    * Called to indicate that the ad will be launching a fullscreen overlay.  
    *  
    * @param ad Represents the [InMobiInterstitial] ad which will display  
    */  
open fun onAdWillDisplay(ad: InMobiInterstitial) {}
/**
    * Called to indicate that the fullscreen overlay is now the topmost screen.  
    *  
    * @param ad   Represents the [InMobiInterstitial] ad which is displayed  
    * @param info Represents the meta info for the ad displayed  
    */  
open fun onAdDisplayed(ad: InMobiInterstitial, info: AdMetaInfo) {}
/**
    * Called to indicate that a request to show an ad (by calling [InMobiInterstitial.show]  
    * failed. You should call [InMobiInterstitial.load] to request for a fresh ad.  
    *  
    * @param ad Represents the [InMobiInterstitial] ad which failed to show  
    */  
open fun onAdDisplayFailed(ad: InMobiInterstitial) {}
/**
    * Called to indicate that the fullscreen overlay opened by the ad was closed.  
    *  
    * @param ad Represents the [InMobiInterstitial] ad which was dismissed  
    */  
open fun onAdDismissed(ad: InMobiInterstitial) {}
/**
    * Called to indicate that the user may leave the application on account of interacting with the ad.  
    *  
    * @param ad Represents the [InMobiInterstitial] ad  
    */  
open fun onUserLeftApplication(ad: InMobiInterstitial) {}
/**
    * Called to indicate that rewards have been unlocked.  
    *  
    * @param ad      Represents the [InMobiInterstitial] ad for which rewards was unlocked  
    * @param rewards Represents the rewards unlocked  
    */  
open fun onRewardsUnlocked(ad: InMobiInterstitial, rewards: Map<any, any="">) {}
/**
     * Called to notify that inmobi has logged an impression for the ad 
     * @param ad     Represents the ad which was impressed 
     */ 
open fun onAdImpression(ad: InMobiInterstitial) {}
}

Loading an Interstitial Ad

To request for an interstitial ad, call the load() method on the InMobiInterstitial instance:

Java

interstitialAd.load();

Kotlin

interstitialAd.load()

InterstitialAdEventListener abstract class notifies the result of this method. If the ad request was successful, the onAdFetchSuccessful(InMobiInterstitial, AdMetaInfo) event is generated. This is followed by either the onAdLoadSucceeded or the onAdLoadFailed event.

If the onAdLoadFailed event is generated, the reason is indicated by the InMobiAdRequestStatus object passed in this event.

If the onAdLoadSucceeded event is generated, you can show the ad anytime after this by calling show() on the InMobiInterstitial instance.

Note

Calling load() on the same interstitial ad after the onAdLoadSucceeded event is generated by the SDK is not guaranteed to request a fresh ad from the network. A fresh ad will only be fetched if either the previous ad was discarded by the SDK, or if the ad expired or the user cleared application data and caches.


Showing an Interstitial Ad

To show an interstitial ad, call show() on the InMobiInterstitial instance anytime after the onAdLoadSucceeded event has been generated by the SDK. The code fragment below illustrates the same.

Java

InMobiInterstitial interstitialAd;
InterstitialAdEventListener mInterstitialAdEventListener = new InterstitialAdEventListener() {
    // implementation for other events 
    // onAdFetchSuccessful, onAdLoadFailed, etc 
    @Override
    public void onAdLoadSucceeded(@NonNull InMobiInterstitial inMobiInterstitial, @NonNull AdMetaInfo info) {
        Log.d(TAG, "Ad can now be shown!");
        mCanShowAd = true;
    }
};
void init() {
    InMobiInterstitial interstitialAd = new InMobiInterstitial(GameActivity.this, 1471550843414 L, mInterstitialAdEventListener);
}
void prepareGameLevel() {
    interstitialAd.load();
}
void handleGameLevelCompleted() {
    If(mCanShowAd) interstitialAd.show();
}

Kotlin

val interstitialAd: InMobiInterstitial 
val mInterstitialAdEventListener = InterstitialAdEventListener() { 
   // implementation for other events 
   // onAdFetchSuccessful, onAdLoadFailed, etc 
   override fun onAdLoadSucceeded(inMobiInterstitial: InMobiInterstitial, info: AdMetaInfo) { 
       Log.d(TAG, "Ad can now be shown!") 
       mCanShowAd = true 
   } 
} 
fun init() { 
   val interstitialAd = InMobiInterstitial(this@GameActivity, 1471550843414L, mInterstitialAdEventListener) 
} 
fun prepareGameLevel() { 
   interstitialAd.load() 
} 
fun handleGameLevelCompleted() { 
   if(mCanShowAd) interstitialAd.show() 
} 

Your application will be notified of the result of this request via the InterstitialAdEventListener abstract class.

If the ad can be shown, the SDK will notify your code by calling on the onAdWillDisplay interface, followed by calling the onAdDisplayed method when the ad is actually presented on the screen.

If the ad cannot be displayed, the onAdDisplayFailed event is generated by the SDK to let your application know that the ad could not be displayed. You can request for a fresh ad by calling load() again to handle this event.

When an interstitial ad is dismissed, your application will be notified in the onAdDismissed callback.

You can check the code samples for interstitial ad integrations on GitHub here.

On This Page

Last Updated on: 10 Oct, 2024