Interstitial

Last Updated on: 19 Sep, 2023

Create Interstitial Ad

INFO

  • If you miss to Initialize the SDK, this method will fail to return a response.
  • Ensure that everything is executed on the main thread.

After your adunitId is generated, you can find it on the Meson UI. Add adunitId into the MesonInterstitial object and pass the ActivityContext.

Kotlin

val interstitialAd = MesonInterstitial(this, "AD_UNIT_ID")

Java

MesonInterstitial interstitialAd = new MesonInterstitial(this, "AD_UNIT_ID");

Register for Callbacks

Track the ad lifecycle for interstitial ads. All the available events for interstitial ads are listed below.

Kotlin

interstitialAd.setAdListener(object : MesonInterstitialAdListener() { 
    override fun onAdImpression(ad: MesonInterstitial, mesonAdData: MesonAdData?) { 
    } 

     override fun onAdDisplayed(ad: MesonInterstitial) { 
    } 

     override fun onAdDisplayFailed(ad: MesonInterstitial) { 
    } 

     override fun onAdDismissed(ad: MesonInterstitial) { 
    } 

     override fun onUserLeftApplication(ad: MesonInterstitial) { 
    } 

     override fun onAdLoadSucceeded(ad: MesonInterstitial) { 
    }  

    override fun onAdLoadFailed(ad: MesonInterstitial, status: MesonAdRequestStatus) { 
    }  

    override fun onAdClicked(ad: MesonInterstitial, params: HashMap<String, Any>) { 
    } 
})

Java

interstitialAd.setAdListener(new MesonInterstitialAdListener() { 
    @Override 
    public void onUserLeftApplication(MesonInterstitial mesonInterstitial) { 
        super.onUserLeftApplication(mesonInterstitial); 
    }  

    @Override 
    public void onAdImpression(MesonInterstitial mesonInterstitial, @Nullable MesonAdData mesonAdData) { 
        super.onAdImpression(mesonInterstitial, mesonAdData); 
    }  

    @Override 
    public void onAdClicked(MesonInterstitial mesonInterstitial, @NonNull HashMap<String, Object> hashMap) { 
        super.onAdClicked(mesonInterstitial, hashMap); 
    }  

    @Override 
    public void onAdLoadFailed(MesonInterstitial mesonInterstitial, @NonNull MesonAdRequestStatus mesonAdRequestStatus) { 
        super.onAdLoadFailed(mesonInterstitial, mesonAdRequestStatus); 
    }  

    @Override 
    public void onAdLoadSucceeded(MesonInterstitial mesonInterstitial) { 
        super.onAdLoadSucceeded(mesonInterstitial); 
    }  

    @Override 
    public void onAdDisplayFailed(@NonNull MesonInterstitial mesonInterstitial) { 
        super.onAdDisplayFailed(mesonInterstitial); 
    }  

    @Override 
    public void onAdDismissed(@NonNull MesonInterstitial mesonInterstitial) { 
        super.onAdDismissed(mesonInterstitial); 
    }  

    @Override 
    public void onAdDisplayed(@NonNull MesonInterstitial mesonInterstitial) { 
        super.onAdDisplayed(mesonInterstitial); 
    } 
});

Load Ad

The publisher can request an interstitial ad by invoking this method. This will request an ad from all demand sources, select a winner, and make it available on the SDK.

Kotlin

//use load() to make your interstitial ad request
interstitialAd.load()

Java

//use load() to make your interstitial ad request
interstitialAd.load();

Show Ad

The ad is available when the load is called. It is shown to the user when the show method is called. It is recommended to call this method in the onAdLoadSucceeded callback method or check isAdReady method to return true and then call the show method.

Kotlin

//Use show() to show the ad, the ad will have to be ready before calling show
interstitialAd.show()

Java

//Use show() to show the ad, the ad will have to be ready before calling show
interstitialAd.show();

Destroy Interstitial Ad

Use this method when the Interstitial ad is no longer needed. We recommend using this onDestroy of the Activity.

Kotlin

interstitialAd.destroy()

Java

interstitialAd.destroy();