Skip to content

Interstitial

Unlike banners, interstitials can only be integrated with code. Below we show a simple example to understand how it works:

class MainActivity : Activity() {
private var interstitialAd: InterstitialAd? = null
override fun onCreate(savedInstanceState: Bundle?) {
...
interstitialAd = InterstitialAd(this, "<Wortise Ad Unit ID>").also {
it.loadAd()
}
}
override fun onDestroy() {
...
interstitialAd?.destroy()
}
fun showInterstitial() {
if (interstitialAd?.isAvailable == true) {
interstitialAd?.showAd(this)
}
}
}

As with banners, a listener can be set to receive the events that happen during the interstitial lifecycle. For this, you need to implement the InterstitialAd.Listener interface as shown in the example below:

interstitialAd.listener = object : InterstitialAd.Listener() {
override fun onInterstitialClicked(ad: InterstitialAd) {
// Invoked when the ad has been clicked
}
override fun onInterstitialDismissed(ad: InterstitialAd) {
// Invoked when the ad has been dismissed
}
override fun onInterstitialFailedToLoad(ad: InterstitialAd,
error: AdError) {
// Invoked when the ad could not be loaded
// (because of an error or no fill)
}
override fun onInterstitialFailedToShow(ad: InterstitialAd,
error: AdError) {
// Invoked when the ad could not be shown
}
override fun onInterstitialImpression(ad: InterstitialAd) {
// Invoked when the ad has generated an impression
}
override fun onInterstitialLoaded(ad: InterstitialAd) {
// Invoked when the ad has been loaded
}
override fun onInterstitialRevenuePaid(ad: InterstitialAd,
data: RevenueData) {
// Invoked when the ad has generated revenue
}
override fun onInterstitialShown(ad: InterstitialAd) {
// Invoked when the ad has been shown
}
}