简体   繁体   English

如何在 Admob 广告的 onAdFailedToLoad() 内添加限制广告加载重试?

[英]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:在关于如何在应用中放置 Admob 插页式广告的指南中,您有以下警告:

Warning: Attempting to load a new ad from the onAdFailedToLoad () method is strongly discouraged.警告:强烈建议不要尝试从onAdFailedToLoad ()方法加载新广告。 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.如果您必须从onAdFailedToLoad ()加载广告,请限制广告加载重试,以避免在网络连接受限等情况下不断失败的广告请求。

I was putting a我正在放一个

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

inside the onAdFailedToLoad () and it seems that this is not the correct one.onAdFailedToLoad () ,这似乎不是正确的。 What is the best practice for doing this type of limit within the onAdFailedToLoad () ?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 :然后在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 .这将限制向MAXIMUM_NUMBER_OF_AD_REQUEST发送新的添加请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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