-
Notifications
You must be signed in to change notification settings - Fork 4
Interstitial Ads
AdManageKit provides a complete interstitial ad stack with AdManager and the fluent InterstitialAdBuilder. Features include loading strategies, automatic retry, frequency controls, splash screen support, and Jetpack Compose utilities.
Library Version: v4.4.4
-
forceShowInterstitial()now respects global loading strategy - New
forceShowInterstitialAlways()for explicit force fetch - Global
interstitialAutoReloadconfig with per-call override - All AdManager methods use global auto-reload config as default
- Smart splash screen with
waitForLoading()in InterstitialAdBuilder - New
isLoading()andshowOrWaitForAd()methods - Frequency controls:
everyNthTime,maxShows,minInterval
dependencies {
implementation 'com.github.i2hammad.AdManageKit:ad-manage-kit:v4.4.4'
implementation 'com.github.i2hammad.AdManageKit:ad-manage-kit-core:v4.4.4'
implementation 'com.github.i2hammad.AdManageKit:ad-manage-kit-billing:v4.4.4'
// Optional - Jetpack Compose
implementation 'com.github.i2hammad.AdManageKit:ad-manage-kit-compose:v4.4.4'
}Set up in your Application.onCreate():
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
BillingConfig.setPurchaseProvider(BillingPurchaseProvider())
AdManageKitConfig.apply {
debugMode = BuildConfig.DEBUG
defaultInterstitialInterval = 20.seconds
autoRetryFailedAds = true
maxRetryAttempts = 3
// Loading strategy (v2.6.0+)
interstitialLoadingStrategy = AdLoadingStrategy.HYBRID
// Auto-reload after showing (v2.8.0+)
interstitialAutoReload = true // default: true
}
}
}Since 4.2.0 you must also call
MobileAds.initialize()yourself, before any ad request — the Next-Gen SDK removed the legacy SDK's silent lazy-init. This snippet covers configuration only. See Home or the sample app'sMyApplication.ktfor the initialization pattern.
private val adManager = AdManager.getInstance()
// Preload
fun preloadInterstitial(activity: Activity) {
adManager.loadInterstitialAd(activity, AD_UNIT_INTERSTITIAL)
}
// Show
fun showInterstitial(activity: Activity) {
adManager.forceShowInterstitial(activity, object : AdManagerCallback() {
override fun onNextAction() {
navigateNext()
}
})
}| Method | Description |
|---|---|
loadInterstitialAd(context, adUnitId) |
Preload and cache ad |
loadInterstitialAdForSplash(context, unit, timeout, callback) |
Splash-friendly with timeout |
forceShowInterstitial(activity, callback) |
Respects loading strategy (v2.8.0+) |
forceShowInterstitialAlways(activity, callback) |
Always force fetch (v2.8.0+) |
showInterstitialIfReady(activity, callback, reloadAd) |
Show only if cached |
showInterstitialAdByTime(activity, callback) |
Time-interval based |
showInterstitialAdByCount(activity, callback, maxCount) |
Count-limited |
showOrWaitForAd(activity, callback, timeout, showDialog) |
Smart splash (v2.7.0+) |
isLoading() |
Check if currently loading (v2.7.0+) |
isReady() |
Check if ad is cached |
forceShowInterstitial() now respects AdManageKitConfig.interstitialLoadingStrategy:
| Strategy | Behavior |
|---|---|
| ON_DEMAND | Always fetch fresh ad with dialog |
| ONLY_CACHE | Show cached if ready, skip otherwise |
| HYBRID | Show cached if ready, fetch fresh otherwise |
| FRESH_WITH_CACHE_FALLBACK | Fetch fresh, fall back to cache if the load fails |
// Set strategy
AdManageKitConfig.interstitialLoadingStrategy = AdLoadingStrategy.HYBRID
// Now respects strategy
AdManager.getInstance().forceShowInterstitial(activity, callback)
// Always force fetch (bypasses strategy)
AdManager.getInstance().forceShowInterstitialAlways(activity, callback)// In Application.onCreate() - start loading early
AdManager.getInstance().loadInterstitialAd(this, adUnitId)
// In SplashActivity - smart wait
AdManager.getInstance().showOrWaitForAd(
activity = this,
callback = object : AdManagerCallback() {
override fun onNextAction() { startMainActivity() }
},
timeoutMillis = 5000,
showDialogIfLoading = true
)The builder provides a fluent API with frequency controls and loading strategies.
InterstitialAdBuilder.with(this)
.adUnit("ca-app-pub-xxx/yyy")
.show { navigateNext() }InterstitialAdBuilder.with(this)
.adUnit("primary-unit")
.fallback("backup-unit")
.loadingStrategy(AdLoadingStrategy.HYBRID)
.everyNthTime(3) // Show every 3rd call
.maxShows(10) // Maximum 10 shows total
.minIntervalSeconds(30) // Minimum 30 seconds between
.timeout(5000) // 5 second timeout
.autoReload(true) // Auto-reload after showing
.onAdShown { /* analytics */ }
.onAdDismissed { /* cleanup */ }
.onFailed { error -> /* handle */ }
.show { navigateNext() }// In Application.onCreate()
AdManager.getInstance().loadInterstitialAd(this, adUnitId)
// In SplashActivity
InterstitialAdBuilder.with(this)
.adUnit(adUnitId)
.waitForLoading() // Smart: shows cached, waits for loading, or force fetches
.timeout(5000) // 5 second max wait
.show { startMainActivity() }Behavior:
| Ad State | Action |
|---|---|
| READY | Shows immediately |
| LOADING | Waits with timeout, shows when ready |
| NOT STARTED | Force fetches with dialog |
// Show every 3rd time
.everyNthTime(3)
// Maximum 5 shows total
.maxShows(5)
// Minimum 30 seconds between shows
.minIntervalSeconds(30)
// Force show (bypass interval)
.force()// Global config
AdManageKitConfig.interstitialAutoReload = false // Disable globally
// Per-call override
InterstitialAdBuilder.with(activity)
.adUnit(adUnitId)
.autoReload(true) // Override global
.show { next() }Priority: Builder .autoReload() > AdManageKitConfig.interstitialAutoReload
@Composable
fun ContentWithInterstitial() {
val showAd = rememberInterstitialAd(
adUnitId = stringResource(R.string.interstitial_feed),
preloadAd = true,
onAdShown = { /* analytics */ },
onAdDismissed = { navigateNext() },
onAdFailedToLoad = { /* handle */ }
)
Button(onClick = showAd) {
Text("Show Ad")
}
}| Helper | Purpose |
|---|---|
rememberInterstitialAd(...) |
Returns lambda to show ad |
InterstitialAdEffect(...) |
Declarative effect with TIME/COUNT/FORCE modes |
rememberInterstitialAdState(...) |
Mutable state with isLoaded, loadAd(), showAd()
|
| Method | Description |
|---|---|
loadInterstitialAd(context, adUnitId) |
Preload ad |
loadInterstitialAdForSplash(...) |
Splash with timeout |
forceShowInterstitial(activity, callback) |
Respects strategy |
forceShowInterstitialAlways(activity, callback) |
Always force fetch |
showInterstitialIfReady(activity, callback, reloadAd) |
Show cached |
showInterstitialAdByTime(activity, callback) |
Time-based |
showInterstitialAdByCount(activity, callback, max) |
Count-based |
showOrWaitForAd(...) |
Smart splash |
isLoading() |
Check loading state |
isReady() |
Check if cached |
preloadAd(context, adUnitId) |
Background preload |
| Method | Description |
|---|---|
.adUnit(id) |
Set primary ad unit (required) |
.fallback(id) / .fallbacks(...)
|
Fallback units |
.loadingStrategy(strategy) |
Override strategy |
.everyNthTime(n) |
Show every Nth call |
.maxShows(count) |
Limit total shows |
.minInterval(ms) / .minIntervalSeconds(s)
|
Minimum interval |
.timeout(ms) / .timeoutSeconds(s)
|
Load timeout |
.autoReload(boolean) |
Override auto-reload |
.waitForLoading() |
Smart splash behavior |
.force() |
Bypass interval |
.onAdShown {} |
Shown callback |
.onAdDismissed {} |
Dismissed callback |
.onFailed {} |
Failure callback |
.show {} |
Execute and show |
.preload() |
Preload without showing |
| Setting | Description | Default |
|---|---|---|
interstitialLoadingStrategy |
Loading strategy | HYBRID |
interstitialAutoReload |
Auto-reload after showing | true |
defaultInterstitialInterval |
Time between ads | 15 seconds |
defaultAdTimeout |
Load timeout | 15 seconds |
autoRetryFailedAds |
Enable retry | true |
maxRetryAttempts |
Max retries | 3 |
-
Configure once in
Application.onCreate() - Use HYBRID strategy for balanced UX and coverage
- Preload on previous screen for better fill rate
- Use frequency controls to protect UX
- Wire billing to skip ads for premium users
- Enable debug mode during development
- Ad Not Loading: Check adUnitId, network, and AdMob config
-
Ad Not Showing: Verify
isReady()and purchase status -
Strategy Not Working: Ensure v2.8.0+ and check
interstitialLoadingStrategy
AdManageKit v3.3.4 | GitHub | API Docs | Report Issue | Buy me a coffee