应用程序处于后台时显示插页式广告
Interstitial ad displaying while app is in background
我将一个插页式广告设置为在 5 分钟后显示,但我不希望它打开,除非用户正在查看该应用程序。测试中存在一个问题,如果您转到另一个应用程序,它仍然会弹出。
当您离开应用程序(主页按钮等)时,您需要在 onPause()
回调中清除 AdListener。
假设您已经在 adView
中设置了 adListener,您可以在 android 调用 onPause
时将他的监听器设置为 null。应该是这样的:
protected void onPause() {
super.onPause();
if(adView != null) {
adView.setAdListener(null);
}
}
我不知道您使用的是什么版本的 admob,但这应该适用于 Google Play 服务。
广告在后台播放后不应显示,这是它的工作原理。
@Override
protected void onPause() {
if (mAdView != null) {
mAdView.pause();
}
super.onPause();
}
@Override
protected void onDestroy() {
if (mAdView != null) {
mAdView.destroy();
}
super.onDestroy();
}
我将一个插页式广告设置为在 5 分钟后显示,但我不希望它打开,除非用户正在查看该应用程序。测试中存在一个问题,如果您转到另一个应用程序,它仍然会弹出。
当您离开应用程序(主页按钮等)时,您需要在 onPause()
回调中清除 AdListener。
假设您已经在 adView
中设置了 adListener,您可以在 android 调用 onPause
时将他的监听器设置为 null。应该是这样的:
protected void onPause() {
super.onPause();
if(adView != null) {
adView.setAdListener(null);
}
}
我不知道您使用的是什么版本的 admob,但这应该适用于 Google Play 服务。
广告在后台播放后不应显示,这是它的工作原理。
@Override
protected void onPause() {
if (mAdView != null) {
mAdView.pause();
}
super.onPause();
}
@Override
protected void onDestroy() {
if (mAdView != null) {
mAdView.destroy();
}
super.onDestroy();
}