简体   繁体   中英

How to add limit ad load retries inside onAdFailedToLoad() in Admob Ads?

Within the guide on how to place Admob interstitial ads in the app, you have the following warning:

Warning: Attempting to load a new ad from the onAdFailedToLoad () method is strongly discouraged. If you must load an ad from onAdFailedToLoad () , limit ad load retries to avoid continuously failed ad requests in situations such as limited network connectivity.

I was putting a

mInterstitialAd.loadAd (new AdRequest.Builder (). build ());

inside the onAdFailedToLoad () and it seems that this is not the correct one. What is the best practice for doing this type of limit within the onAdFailedToLoad () ?

Maybe create the maximum number of new requests?

const val MAXIMUM_NUMBER_OF_AD_REQUEST = 5

class MainActivity : AppCompatActivity()
{
    private var loadAdInterstitialRequests = 0
}

And then in AdListener :

override fun onAdFailedToLoad(p0: Int)
{
    super.onAdFailedToLoad(p0)
    if (loadAdInterstitialRequests++ < MAXIMUM_NUMBER_OF_AD_REQUEST)
    {
        mInterstitialAd.loadAd(AdRequest.Builder().build())
    }
}

This will limit sending new add requests to MAXIMUM_NUMBER_OF_AD_REQUEST .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM