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

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

在有关如何在应用中放置 Admob 插页式广告的指南中,您收到以下警告:

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.

我正在放一个

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

onAdFailedToLoad () 里面,这似乎不是正确的。 在 onAdFailedToLoad () 范围内进行此类限制的最佳做法是什么?

也许创建了最大数量的新请求?

const val MAXIMUM_NUMBER_OF_AD_REQUEST = 5

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

然后在AdListener:

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

这将限制向 MAXIMUM_NUMBER_OF_AD_REQUEST 发送新的添加请求。