md sohan
md sohan

Reputation: 73

Is Admob Interstitial ad recall itself if failed to load?

I just wanna know, If Interstitial ad failed to load at first time, is it gonna recall itself after some time to load again? or I have to recall it manually by onAdFailedToLoad handler?

Upvotes: 2

Views: 295

Answers (1)

Vasily Kabunov
Vasily Kabunov

Reputation: 6761

If you want to load the ad after an error again, you need to do it manually. I would advice to wait some time before calling ad again.

In my app I use coroutine to schedule second ad loading after 30 sec delay in case of error:

fun requestNewAd() {
    InterstitialAd.load(
        context,
        admobInterstitialUnitId,
        AdRequest.Builder().build(),
        object : InterstitialAdLoadCallback() {
            override fun onAdLoaded(ad: InterstitialAd) {
                ...
            }

            override fun onAdFailedToLoad(e: LoadAdError) {
                ...
                requestNewAdAgain()
            }
        })
}

private var reloadAdAfterErrorJob: Job? = null
fun requestNewAdAgain() {
    reloadAdAfterErrorJob?.cancel()
    reloadAdAfterErrorJob = GlobalScope.launch(Dispatchers.Main) {
        delay(DELAY_AFTER_FAILED_REQUEST_MS)
        requestNewAd()
    }
}

companion object {
    private const val DELAY_AFTER_FAILED_REQUEST_MS = 30 * 1000L // 30 sec
}

Upvotes: 1

Related Questions