How to pause interstitial Ads when Android application goes to background?(Android应用程序进入后台时如何暂停插页式广告?)
问题描述
我在使用适用于 Android 的 admob 的插页式广告方面遇到问题,即使我点击主页按钮或转到后台,商业视频仍在播放.有没有人知道如何解决这个问题?
I have an issues with interstitial ad using admob for Android, which is the commercial video still running even I tap home button or goes to background. Is there anyone knows how to fix this issue?
我已经搜索了一整天,但找不到它.有人说我们无法控制广告.但是当我们点击设备上的主页按钮或应用程序进入后台时,Youtube android 应用程序能够暂停.
I've searched all day long, but couldn't find it. Some says that we can't control the ad. But when Youtube android application is able to pause whenever we tap on Home Button on device or the app goes to background.
推荐答案
您使用的是什么版本的 AdMob SDK?此解决方案适用于 Google Play 服务.
What version of the AdMob SDK are you using? This solution will work with Google Play Services.
假设这是您设置插页式广告的方式:
Lets say that this is how you setup your interstitial:
//Here is where you setup your interstitial
//...
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded(){
adView.show();
}
});
在您的 onPause() 方法中,您可以执行以下操作:
In your onPause() method you can do the following:
protected void onPause() {
super.onPause();
if(adView != null) {
adView.setAdListener(null);
}
}
之所以有效,是因为当 onPause 方法因新的插页式广告而被调用时,广告已经处于展示过程中并且会正常展示.但是,如果由于其他原因(例如按下 Home 按钮)调用 onPause(),它将禁止显示新的插页式广告.
This works because by the time the onPause method is called because of a new interstitial, the ad will already be in the process of being shown and will display normally. However, if onPause() is called because of something else, like the Home button being pressed, it will disable new interstitials from being shown.
唯一需要注意的是,如果您使用的是 AdListener 提供的其他回调方法.
Only caveat is if you're using other callback methods available from the AdListener.
这篇关于Android应用程序进入后台时如何暂停插页式广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android应用程序进入后台时如何暂停插页式广告?
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01