Ads are loading, but not showing?(广告正在加载,但未展示?)
问题描述
我的插页式广告已成功加载,但是当我对它们调用 .show()
时,它们没有显示出来.
My interstitial ads are successfully loading, but when I call .show()
on them, they don't show up.
我已按照 这些 说明操作,广告加载成功,但是当我调用 mInterstitialAd.show();
:
I have followed these directions, and the ads load successfully, but don't show when I call mInterstitialAd.show();
:
在 onCreate() 中:
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("My ID");
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
beginPlayingGame();
}
});
requestNewInterstitial();
requestNewInterstitial()
:
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("Phone's ID")
.build();
mInterstitialAd.loadAd(adRequest);
}
问题来了:
public void tryAgain(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
Log.v(TAG, "LOADED in Game Over!");
}
else {
beginPlayingGame();
}
beginPlayingGame();
}
我收到日志说它已加载到我的日志猫中,但广告实际上并未显示!为什么会加载,但不显示?
I get the log saying it is loaded in my log cat, but the ad doesn't actually show! Why is it loading, but not showing?
附:我想我实际上更早地让它工作了一次,但从那以后它就停止了工作.可能是什么问题?
P.S. I think I actually got it to work once earlier, but it stopped working ever since then. What could be the problem?
推荐答案
原来我只需要删除 else 之后的额外方法调用.例如,
It turns out that I just had to remove the extra method call after the else. For example,
public void tryAgain(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
Log.v(TAG, "LOADED in Game Over!");
}
else {
beginPlayingGame();
}
beginPlayingGame();
}
应该是
public void tryAgain(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
Log.v(TAG, "LOADED in Game Over!");
}
else {
beginPlayingGame();
}
//NOTICE THERE Is NO EXTRA METHOD CALL OF **beginPlayingGame()**
}
这篇关于广告正在加载,但未展示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:广告正在加载,但未展示?
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 获取数字的最后一位 2022-01-01
- 转换 ldap 日期 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01