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()**
}
这篇关于广告正在加载,但未展示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:广告正在加载,但未展示?
基础教程推荐
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01