当我单击“后退”按钮或从上一个活动返回时,则会显示插页式广告。但是我想在用户从活动1转到活动2时展示广告。当我稍稍更改代码时,插页式广告就会显示,但是它阻止了用户将其转到活动2。
在执行活动1的活动2后,按下返回按钮时显示插页式广告的代码。
public void ok(View view) {
if (InterstitialAd.isLoaded())
InterstitialAd.show();
Intent intent = new Intent ( WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(this, WallpaperService.class));
startActivity(intent);
}
显示插页式广告但阻止用户进行活动2的代码
public void ok(View view) {
Intent intent = new Intent ( WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(this, WallpaperService.class));
startActivity(intent);
if (InterstitialAd.isLoaded())
InterstitialAd.show();
}
答案 0 :(得分:0)
我认为您应该使用这样的东西:
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mInterstitialAd.loadAd(adRequest);
startActivity(intent);
Log.i("Ads", "onAdClosed");
}
});
} else {
startActivity(intent);
}
这意味着当您关闭广告时,它将引导您进入预期的活动。而且,如果没有广告加载,那么它将立即带您进入下一个活动。
在您的情况下,请尝试:
public void ok(View view) {
if (InterstitialAd.isLoaded()) {
InterstitialAd.show();
Intent intent = new Intent ( WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(this, WallpaperService.class));
InterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
InterstitialAd.loadAd(adRequest);
startActivity(intent);
Log.i("Ads", "onAdClosed");
}
});
} else {
startActivity(intent);
}
}