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

huangapple go评论68阅读模式
英文:

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

问题

在关于如何在应用中放置 AdMob 插页式广告的指南中,您会看到以下警告:

>警告:强烈不建议尝试从 onAdFailedToLoad() 方法中加载新广告。如果必须从 onAdFailedToLoad() 加载广告,则应限制广告加载的重试次数,以避免在网络连接有限等情况下不断失败的广告请求。

我曾经将下面的代码放在 onAdFailedToLoad() 方法中,但似乎这不是正确的方法:

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

onAdFailedToLoad() 中进行此类限制的最佳实践是什么?

英文:

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 ()?

答案1

得分: 1

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

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

英文:

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++ &lt; MAXIMUM_NUMBER_OF_AD_REQUEST)
    {
        mInterstitialAd.loadAd(AdRequest.Builder().build())
    }
}

This will limit sending new add requests to MAXIMUM_NUMBER_OF_AD_REQUEST.

huangapple
  • 本文由 发表于 2020年9月8日 07:11:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63785243.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定