Interstitial Ads

Integrate CloudX interstitial ads in Android apps

CloudX-rendered creatives

CloudX-served creatives are rendered by the built-in renderer, which ships inside the core SDK — no separate renderer adapter module is required. The creative type is selected automatically from the bid response, so no publisher integration is needed to render either format. The renderer supports MRAID 3.0 (HTML) and VAST creatives across the ad formats:

Ad formatHTML (MRAID 3.0)VAST
Banner
MREC
Interstitial
Rewarded
class MainActivity : AppCompatActivity(), CloudXInterstitialListener, CloudXAdRevenueListener {
    private lateinit var interstitialAd: CloudXInterstitialAd
    private var retryAttempt = 0

    private fun createInterstitialAd() {
        interstitialAd = CloudX.createInterstitial(this, "your-interstitial-ad-unit-id")
        interstitialAd.listener = this
        interstitialAd.revenueListener = this
        interstitialAd.load()
    }

    private fun showInterstitialAd() {
        if (interstitialAd.isAdReady) {
            // Basic show
            interstitialAd.show(this)

            // Or with optional placement and custom data for tracking
            // interstitialAd.show(this, "level_complete", "level:5,score:1000")
        } else {
            Log.w("CloudX", "Interstitial ad not ready yet")
        }
    }

    // CloudXInterstitialListener callbacks
    override fun onAdLoaded(cloudXAd: CloudXAd) {
        Log.d("CloudX", "Interstitial ad loaded from ${cloudXAd.networkName}")
        retryAttempt = 0
    }

    /**
     * Retries loading with exponential backoff: delay doubles with each attempt
     * (2s → 4s → 8s … 32s max) to avoid hammering the server during transient
     * failures. [retryAttempt] resets to 0 in [onAdLoaded].
     */
    override fun onAdLoadFailed(adUnitId: String, cloudXError: CloudXError) {
        Log.e("CloudX", "Interstitial ad failed to load: ${cloudXError.message}")
        retryAttempt++
        val delayMillis = TimeUnit.SECONDS.toMillis(2.0.pow(retryAttempt.coerceAtMost(5)).toLong())
        Handler(Looper.getMainLooper()).postDelayed({ interstitialAd.load() }, delayMillis)
    }

    override fun onAdDisplayed(cloudXAd: CloudXAd) {
        Log.d("CloudX", "Interstitial ad displayed")
    }

    override fun onAdDisplayFailed(cloudXAd: CloudXAd, cloudXError: CloudXError) {
        Log.e("CloudX", "Interstitial ad failed to display: ${cloudXError.message}")
        interstitialAd.load()
    }

    override fun onAdHidden(cloudXAd: CloudXAd) {
        Log.d("CloudX", "Interstitial ad hidden")
        // Reload for next use
        interstitialAd.load()
    }

    override fun onAdClicked(cloudXAd: CloudXAd) {
        Log.d("CloudX", "Interstitial ad clicked")
    }

    // CloudXAdRevenueListener callback
    override fun onAdRevenuePaid(cloudXAd: CloudXAd) {
        Log.d("CloudX", "Interstitial bid-time revenue: ${cloudXAd.revenue} from ${cloudXAd.networkName}")
    }

    override fun onDestroy() {
        super.onDestroy()
        interstitialAd.destroy()
    }
}