英文:
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++ < MAXIMUM_NUMBER_OF_AD_REQUEST)
{
mInterstitialAd.loadAd(AdRequest.Builder().build())
}
}
This will limit sending new add requests to MAXIMUM_NUMBER_OF_AD_REQUEST
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论