Overview
Interstitial ads are full-screen ads that cover the entire interface of the app. They are best suited for natural transition points in the app, such as game level transitions or content page changes.
Features
Full-screen immersive ads
Remain visible until explicitly closed by the user
Support for image and video ads
High visual attention
Use the test unit ID for development: PUBLIC_TEST_UNIT_ID_INTERSTITIAL
Implementation Steps
Interstitial ads are implemented in 4 steps:
Initialize - Create AdropInterstitialAd instance
Set Listener - Configure listener for ad events
Load Ad - Request and receive ads
Show Ad - Display the ad on screen
Basic Implementation
Creating AdropInterstitialAd Instance
import io.adrop.ads.interstitial.AdropInterstitialAd
class MainActivity : AppCompatActivity () {
private var interstitialAd: AdropInterstitialAd ? = null
override fun onCreate (savedInstanceState: Bundle ?) {
super . onCreate (savedInstanceState)
setContentView (R.layout.activity_main)
// 1. Create interstitial ad instance
interstitialAd = AdropInterstitialAd ( this , "YOUR_UNIT_ID" )
}
}
AdropInterstitialAd Constructor
Android Context object (Activity or Application Context)
Ad unit ID (issued from console)
Setting Listener
To receive ad events, implement and set AdropInterstitialAdListener.
import io.adrop.ads.interstitial.AdropInterstitialAdListener
import io.adrop.ads.model.AdropErrorCode
class MainActivity : AppCompatActivity () {
private var interstitialAd: AdropInterstitialAd ? = null
override fun onCreate (savedInstanceState: Bundle ?) {
super . onCreate (savedInstanceState)
setContentView (R.layout.activity_main)
// 1. Create interstitial ad instance
interstitialAd = AdropInterstitialAd ( this , "YOUR_UNIT_ID" )
// 2. Set listener
interstitialAd?.interstitialAdListener = object : AdropInterstitialAdListener {
override fun onAdReceived (ad: AdropInterstitialAd ) {
Log. d ( "Adrop" , "Interstitial ad received" )
}
override fun onAdFailedToReceive (ad: AdropInterstitialAd , errorCode: AdropErrorCode ) {
Log. e ( "Adrop" , "Interstitial ad failed to receive: $errorCode " )
}
override fun onAdImpression (ad: AdropInterstitialAd ) {
Log. d ( "Adrop" , "Interstitial ad impression" )
}
override fun onAdClicked (ad: AdropInterstitialAd ) {
Log. d ( "Adrop" , "Interstitial ad clicked" )
}
override fun onAdWillPresentFullScreen (ad: AdropInterstitialAd ) {
Log. d ( "Adrop" , "Interstitial ad will present" )
}
override fun onAdDidPresentFullScreen (ad: AdropInterstitialAd ) {
Log. d ( "Adrop" , "Interstitial ad did present" )
}
override fun onAdWillDismissFullScreen (ad: AdropInterstitialAd ) {
Log. d ( "Adrop" , "Interstitial ad will dismiss" )
}
override fun onAdDidDismissFullScreen (ad: AdropInterstitialAd ) {
Log. d ( "Adrop" , "Interstitial ad dismissed" )
// Preload next ad
loadInterstitialAd ()
}
override fun onAdFailedToShowFullScreen (ad: AdropInterstitialAd , errorCode: AdropErrorCode ) {
Log. e ( "Adrop" , "Interstitial ad failed to show: $errorCode " )
}
}
// 3. Load ad
loadInterstitialAd ()
}
private fun loadInterstitialAd () {
interstitialAd?. load ()
}
}
Loading Ad
Call the load() method to request an ad.
private fun loadInterstitialAd () {
interstitialAd?. load ()
}
The onAdReceived callback is called when the ad is successfully loaded, and onAdFailedToReceive is called when loading fails.
Showing Ad
Call the show() method to display the ad after it’s loaded.
isLoaded Property
A property to check if the ad is loaded. It’s recommended to check this value before calling show().
private fun showInterstitialAd () {
if (interstitialAd?.isLoaded == true ) {
interstitialAd?. show ( this )
} else {
Log. d ( "Adrop" , "Ad is not loaded yet" )
}
}
show Method
Activity object to display the ad
AdropInterstitialAd Properties
unitId
Returns the ad unit ID.
val unitId: String = interstitialAd?.unitId ?: ""
isLoaded
Returns whether the ad is loaded.
val isLoaded: Boolean = interstitialAd?.isLoaded ?: false
creativeId
Returns the creative ID of the currently loaded ad.
val creativeId: String = interstitialAd?.creativeId ?: ""
txId
Returns the transaction ID of the currently loaded ad.
val txId: String = interstitialAd?.txId ?: ""
campaignId
Returns the campaign ID of the currently loaded ad.
val campaignId: String = interstitialAd?.campaignId ?: ""
isBackfilled
Returns whether the currently loaded ad is a backfill ad.
val isBackfilled: Boolean = interstitialAd?.isBackfilled ?: false
AdropInterstitialAdListener Methods
Required Methods
onAdReceived
(AdropInterstitialAd) -> Unit
Called when ad is successfully received. You can call show() to display the ad from this point.
onAdFailedToReceive
(AdropInterstitialAd, AdropErrorCode) -> Unit
Called when ad fails to load. Check the error code for the failure reason.
Optional Methods
onAdImpression
(AdropInterstitialAd) -> Unit
Called when an ad impression is recorded.
onAdClicked
(AdropInterstitialAd) -> Unit
Called when the user clicks the ad.
onAdWillPresentFullScreen
(AdropInterstitialAd) -> Unit
Called just before the interstitial ad is displayed. You can pause game logic here.
onAdDidPresentFullScreen
(AdropInterstitialAd) -> Unit
Called immediately after the interstitial ad is displayed on screen.
onAdWillDismissFullScreen
(AdropInterstitialAd) -> Unit
Called just before the interstitial ad is closed.
onAdDidDismissFullScreen
(AdropInterstitialAd) -> Unit
Called immediately after the interstitial ad is closed. Good time to preload the next ad.
onAdFailedToShowFullScreen
(AdropInterstitialAd, AdropErrorCode) -> Unit
Called when ad fails to show. Check the error code for the failure reason.
Lifecycle Management
destroy Method
You must call destroy() to release resources when the Activity or Fragment is destroyed.
override fun onDestroy () {
super . onDestroy ()
interstitialAd?. destroy ()
interstitialAd = null
}
Always call destroy() to prevent memory leaks.
Preloading Strategy
It’s recommended to preload ads for better user experience.
Basic Preloading
class GameActivity : AppCompatActivity () {
private var interstitialAd: AdropInterstitialAd ? = null
private var isAdReady = false
override fun onCreate (savedInstanceState: Bundle ?) {
super . onCreate (savedInstanceState)
setContentView (R.layout.activity_game)
// Preload on screen entry
preloadInterstitialAd ()
}
private fun preloadInterstitialAd () {
interstitialAd = AdropInterstitialAd ( this , "YOUR_UNIT_ID" )
interstitialAd?.interstitialAdListener = object : AdropInterstitialAdListener {
override fun onAdReceived (ad: AdropInterstitialAd ) {
isAdReady = true
Log. d ( "Adrop" , "Interstitial ad ready" )
}
override fun onAdFailedToReceive (ad: AdropInterstitialAd , errorCode: AdropErrorCode ) {
isAdReady = false
Log. e ( "Adrop" , "Interstitial ad load failed: $errorCode " )
}
override fun onAdDidDismissFullScreen (ad: AdropInterstitialAd ) {
isAdReady = false
// Preload next ad
preloadInterstitialAd ()
}
}
interstitialAd?. load ()
}
private fun onGameLevelComplete () {
// Show immediately on level complete
if (isAdReady) {
interstitialAd?. show ( this )
}
}
}
Reload After Dismiss
Preload the next ad in the onAdDidDismissFullScreen callback after the ad is closed.
override fun onAdDidDismissFullScreen (ad: AdropInterstitialAd ) {
Log. d ( "Adrop" , "Interstitial ad dismissed" )
// Immediately load next ad
interstitialAd?. load ()
}
Best Practices
1. Appropriate Display Timing
Show ads at natural transition points in the app.
// Good: Game level transition
fun onLevelComplete () {
saveProgress ()
showInterstitialAd ()
loadNextLevel ()
}
// Good: Content reading complete
fun onArticleFinished () {
showInterstitialAd ()
}
// Bad: During user action
fun onButtonClick () {
showInterstitialAd () // Disrupts user experience
performAction ()
}
2. Error Handling
Implement handling for ad load failures.
override fun onAdFailedToReceive (ad: AdropInterstitialAd , errorCode: AdropErrorCode ) {
when (errorCode) {
AdropErrorCode.ERROR_CODE_NETWORK -> {
Log. e ( "Adrop" , "Network error: try again later" )
retryAfterDelay ()
}
AdropErrorCode.ERROR_CODE_AD_NO_FILL -> {
Log. w ( "Adrop" , "No ads available" )
continueWithoutAd ()
}
else -> {
Log. e ( "Adrop" , "Ad load failed: $errorCode " )
}
}
}
private fun retryAfterDelay () {
Handler (Looper. getMainLooper ()). postDelayed ({
interstitialAd?. load ()
}, 30000 ) // Retry after 30 seconds
}
private fun continueWithoutAd () {
// Continue without ad
proceedToNextScreen ()
}
3. Frequency Capping
Don’t show ads too frequently.
class AdFrequencyManager {
private var lastAdShownTime: Long = 0
private val minimumInterval = 180_000L // 3 minutes
fun canShowAd (): Boolean {
val currentTime = System. currentTimeMillis ()
return currentTime - lastAdShownTime >= minimumInterval
}
fun recordAdShown () {
lastAdShownTime = System. currentTimeMillis ()
}
}
// Usage example
class MainActivity : AppCompatActivity () {
private val frequencyManager = AdFrequencyManager ()
private fun showInterstitialIfAllowed () {
if ( ! frequencyManager. canShowAd ()) {
Log. d ( "Adrop" , "Ad display interval too short" )
return
}
interstitialAd?. show ( this )
}
// Call in listener
override fun onAdDidPresentFullScreen (ad: AdropInterstitialAd ) {
frequencyManager. recordAdShown ()
}
}
4. Game Pause Handling
Pause games or animations when showing interstitial ads.
override fun onAdWillPresentFullScreen (ad: AdropInterstitialAd ) {
// Pause game
pauseGame ()
// Stop background music
pauseBackgroundMusic ()
}
override fun onAdDidDismissFullScreen (ad: AdropInterstitialAd ) {
// Resume game
resumeGame ()
// Resume background music
resumeBackgroundMusic ()
}
Testing
Using Test Unit ID
Use test unit IDs during development.
import io.adrop.ads.AdropAds
class MainActivity : AppCompatActivity () {
private val unitId = if (BuildConfig.DEBUG) {
"PUBLIC_TEST_UNIT_ID_INTERSTITIAL"
} else {
"YOUR_PRODUCTION_UNIT_ID"
}
override fun onCreate (savedInstanceState: Bundle ?) {
super . onCreate (savedInstanceState)
setContentView (R.layout.activity_main)
interstitialAd = AdropInterstitialAd ( this , unitId)
}
}
Verify Ad Load
Verify that ads are loading correctly.
override fun onAdReceived (ad: AdropInterstitialAd ) {
Log. d ( "Adrop" , "Interstitial ad load success" )
Log. d ( "Adrop" , "Unit ID: ${ ad.unitId } " )
Log. d ( "Adrop" , "Creative ID: ${ ad.creativeId } " )
Log. d ( "Adrop" , "Is Backfilled: ${ ad.isBackfilled } " )
}
override fun onAdFailedToReceive (ad: AdropInterstitialAd , errorCode: AdropErrorCode ) {
Log. e ( "Adrop" , "Interstitial ad load failed: $errorCode " )
if (BuildConfig.DEBUG) {
Toast. makeText ( this , "Ad load failed: $errorCode " , Toast.LENGTH_SHORT). show ()
}
}
Complete Implementation Example
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import io.adrop.ads.interstitial.AdropInterstitialAd
import io.adrop.ads.interstitial.AdropInterstitialAdListener
import io.adrop.ads.model.AdropErrorCode
class InterstitialAdActivity : AppCompatActivity () {
private var interstitialAd: AdropInterstitialAd ? = null
private lateinit var loadButton: Button
private lateinit var showButton: Button
override fun onCreate (savedInstanceState: Bundle ?) {
super . onCreate (savedInstanceState)
setContentView (R.layout.activity_interstitial_ad)
loadButton = findViewById (R.id.btn_load_ad)
showButton = findViewById (R.id.btn_show_ad)
// Set initial button state
showButton.isEnabled = false
// Initialize interstitial ad
setupInterstitialAd ()
// Button click listeners
loadButton. setOnClickListener {
loadInterstitialAd ()
}
showButton. setOnClickListener {
showInterstitialAd ()
}
// Auto-load first ad
loadInterstitialAd ()
}
private fun setupInterstitialAd () {
val unitId = if (BuildConfig.DEBUG) {
"PUBLIC_TEST_UNIT_ID_INTERSTITIAL"
} else {
"YOUR_PRODUCTION_UNIT_ID"
}
interstitialAd = AdropInterstitialAd ( this , unitId)
interstitialAd?.interstitialAdListener = object : AdropInterstitialAdListener {
override fun onAdReceived (ad: AdropInterstitialAd ) {
Log. d (TAG, "Interstitial ad received" )
showButton.isEnabled = true
loadButton.isEnabled = false
Toast. makeText (
this@InterstitialAdActivity ,
"Ad is ready" ,
Toast.LENGTH_SHORT
). show ()
}
override fun onAdFailedToReceive (ad: AdropInterstitialAd , errorCode: AdropErrorCode ) {
Log. e (TAG, "Interstitial ad failed to receive: $errorCode " )
showButton.isEnabled = false
loadButton.isEnabled = true
Toast. makeText (
this@InterstitialAdActivity ,
"Ad load failed: $errorCode " ,
Toast.LENGTH_SHORT
). show ()
}
override fun onAdImpression (ad: AdropInterstitialAd ) {
Log. d (TAG, "Interstitial ad impression" )
}
override fun onAdClicked (ad: AdropInterstitialAd ) {
Log. d (TAG, "Interstitial ad clicked" )
}
override fun onAdWillPresentFullScreen (ad: AdropInterstitialAd ) {
Log. d (TAG, "Interstitial ad will present" )
}
override fun onAdDidPresentFullScreen (ad: AdropInterstitialAd ) {
Log. d (TAG, "Interstitial ad did present" )
}
override fun onAdWillDismissFullScreen (ad: AdropInterstitialAd ) {
Log. d (TAG, "Interstitial ad will dismiss" )
}
override fun onAdDidDismissFullScreen (ad: AdropInterstitialAd ) {
Log. d (TAG, "Interstitial ad dismissed" )
showButton.isEnabled = false
loadButton.isEnabled = true
Toast. makeText (
this@InterstitialAdActivity ,
"Ad closed" ,
Toast.LENGTH_SHORT
). show ()
// Preload next ad
loadInterstitialAd ()
}
override fun onAdFailedToShowFullScreen (ad: AdropInterstitialAd , errorCode: AdropErrorCode ) {
Log. e (TAG, "Interstitial ad failed to show: $errorCode " )
showButton.isEnabled = false
loadButton.isEnabled = true
Toast. makeText (
this@InterstitialAdActivity ,
"Ad show failed: $errorCode " ,
Toast.LENGTH_SHORT
). show ()
}
}
}
private fun loadInterstitialAd () {
Log. d (TAG, "Loading interstitial ad" )
loadButton.isEnabled = false
interstitialAd?. load ()
}
private fun showInterstitialAd () {
if (interstitialAd?.isLoaded == true ) {
Log. d (TAG, "Showing interstitial ad" )
interstitialAd?. show ( this )
} else {
Log. w (TAG, "Ad is not loaded yet" )
Toast. makeText ( this , "Ad is not ready" , Toast.LENGTH_SHORT). show ()
}
}
override fun onDestroy () {
super . onDestroy ()
interstitialAd?. destroy ()
interstitialAd = null
}
companion object {
private const val TAG = "InterstitialAdActivity"
}
}
Troubleshooting
onAdReceived is not called
Verify SDK is initialized
Check unit ID is correct
Check network connection
Verify AndroidManifest.xml has internet permission
onAdFailedToReceive is called
Check the error code to identify the issue
ERROR_CODE_AD_NO_FILL: No ad inventory, try again later
ERROR_CODE_NETWORK: Check network connection
ERROR_CODE_INVALID_UNIT: Verify unit ID
Nothing happens after show() is called
Ensure show() is called after onAdReceived callback
Check isLoaded property is true
Verify Activity is valid
Ensure another interstitial ad is not already showing
Verify destroy() is called in onDestroy()
Check Context reference is managed with WeakReference
Ensure listener is set to null
Next Steps