【发布时间】:2018-03-13 12:18:23
【问题描述】:
我在不同的活动中加载横幅广告和插页式广告。问题是广告在某些地方加载良好,而在某些地方,它们根本没有加载。我使用相同的方法在整个应用程序中加载广告,为什么它们在某些时候没有加载?这是插页式广告的代码,在启动画面中运行良好:
setContentView(R.layout.splash);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.AdUnitId_interstitial));
requestNewInterstitial();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
requestNewInterstitial();
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
}
});
}
finish();
}
}, SPLASH_TIME_OUT);
}
相同的代码在抽屉活动中不起作用。这是onCreate中的代码:
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.AdUnitId_interstitial));
requestNewInterstitial();
这是按钮点击处理程序的代码:
else if (id == R.id.audio) {
startActivity(new Intent(MainActivity.this, AndroidBuildingMusicPlayerActivity.class));
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
requestNewInterstitial();
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
}
});
}
对于横幅广告,我正在使用这个:
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest1 = new AdRequest.Builder().build();
mAdView.loadAd(adRequest1);
它在一些活动中运行良好,但在某些活动中不起作用。有人知道吗?
【问题讨论】:
标签: android adview banner-ads