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 format | HTML (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()
}
}public class MainActivity extends AppCompatActivity implements CloudXInterstitialListener, CloudXAdRevenueListener {
private CloudXInterstitialAd interstitialAd;
private int retryAttempt;
private void createInterstitialAd() {
interstitialAd = CloudX.createInterstitial(this, "your-interstitial-ad-unit-id");
interstitialAd.setListener(this);
interstitialAd.setRevenueListener(this);
interstitialAd.load();
}
private void 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");
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (interstitialAd != null) {
interstitialAd.destroy();
}
}
// CloudXInterstitialListener callbacks
@Override
public void onAdLoaded(@NonNull CloudXAd cloudXAd) {
Log.d("CloudX", "Interstitial ad loaded from " + cloudXAd.getNetworkName());
retryAttempt = 0;
}
@Override
public void onAdLoadFailed(@NonNull String adUnitId, @NonNull CloudXError cloudXError) {
Log.e("CloudX", "Interstitial ad failed to load: " + cloudXError.getMessage());
retryAttempt++;
long delayMillis = TimeUnit.SECONDS.toMillis((long) Math.pow(2, Math.min(5, retryAttempt)));
new Handler(Looper.getMainLooper()).postDelayed(() -> interstitialAd.load(), delayMillis);
}
@Override
public void onAdDisplayed(@NonNull CloudXAd cloudXAd) {
Log.d("CloudX", "Interstitial ad displayed");
}
@Override
public void onAdDisplayFailed(@NonNull CloudXAd cloudXAd, @NonNull CloudXError cloudXError) {
Log.e("CloudX", "Interstitial ad failed to display: " + cloudXError.getMessage());
interstitialAd.load();
}
@Override
public void onAdHidden(@NonNull CloudXAd cloudXAd) {
Log.d("CloudX", "Interstitial ad hidden");
// Reload for next use
interstitialAd.load();
}
@Override
public void onAdClicked(@NonNull CloudXAd cloudXAd) {
Log.d("CloudX", "Interstitial ad clicked");
}
// CloudXAdRevenueListener callback
@Override
public void onAdRevenuePaid(@NonNull CloudXAd cloudXAd) {
Log.d("CloudX", "Interstitial bid-time revenue: " + cloudXAd.getRevenue() + " from " + cloudXAd.getNetworkName());
}
}Ad readiness
isAdReady is true from the moment an ad loads until you show it or destroy the ad object. An ad network can stop being able to show an ad without telling the SDK. isAdReady stays true in that case, and the problem is found when you call show(). If the network does report that its ad has expired, the ad is no longer ready.
- If you call
show()on an ad the network can no longer show,onAdDisplayFailedfires and the ad is no longer ready. Callload()to get a new ad. - In that case, if CloudX has enabled show recovery for your app and ad unit, the SDK loads a replacement and shows it instead. You receive the replacement’s display and revenue callbacks, and no
onAdDisplayFailed. If an expired-ad replacement is already loading, the SDK uses it, andonExpiredAdReloadedfires before it is shown. If no replacement loads, or none is ready within the time limit CloudX sets,onAdDisplayFailedfires. - If you call
load()while an ad is ready, no new request starts.onAdLoadedfires at once with that ad. - A
load()call while an ad is showing runs after the ad closes. Aload()call whileshow()waits for a recovery replacement also runs after the show ends, and receives exactly oneonAdLoadedoronAdLoadFailed.
Expired ads
A loaded ad that is not shown before it expires is reloaded automatically on the same ad object. The current ad stays ready and can still be shown until the replacement is ready.
- To be told when a replacement is ready, set an
expirationListener. A replacement that loads on its own does not callonAdLoadedagain. - If you show the ad while the replacement loads, the replacement is kept. If it is ready when the ad closes, or no
load()comes before it is ready, it becomes ready on the ad object and theexpirationListeneris called then. If you callload()after the ad closes while the replacement is still loading, thatload()runs its own request and getsonAdLoaded, and noexpirationListenercall follows for that replacement. - If you call
load()while the expired ad is still loaded, no new request starts.onAdLoadedfires at once with the expired ad. The replacement keeps loading, and theexpirationListeneris called when it is ready. - If the replacement fails to load while the expired ad is still loaded,
onAdLoadFailedfires and the ad is no longer ready. Reload and its retries are set per ad unit by CloudX, and retries are off by default, so one no-fill ends here. This is the normal outcome, not an integration error: callload()again after a delay rather than in a tight loop.
interstitialAd.expirationListener = CloudXAdExpirationListener { expiredAd, newAd ->
Log.d("CloudX", "Expired interstitial ad replaced by an ad from ${newAd.networkName}")
}interstitialAd.setExpirationListener((expiredAd, newAd) ->
Log.d("CloudX", "Expired interstitial ad replaced by an ad from " + newAd.getNetworkName()));