如果用户单击Android主页按钮,如何自动关闭admob插页式广告? [英] How to automatically close admob interstitial ad if users click the Android home button?

查看:421
本文介绍了如果用户单击Android主页按钮,如何自动关闭admob插页式广告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Android应用中使用了Admob的插页式广告。在应用的某些事件中会调用interstitialAd.show()。一切正常,但有一个烦人的广告用例。

I was using the interstitial ad from Admob in my android app. The interstitialAd.show() is called at certain events of the app. Everything worked fine but one annoying use case with the ad.

如果用户在广告展示时单击HOME或广告活动(即用户单击广告)处于活动状态,广告或广告活动将在切换回应用后显示。我希望显示该应用程序(即主要活动位于活动堆栈的顶部),因为它会使用户首先看到广告感到困惑。

If users click HOME while the ad is displaying or the ad activity (i.e. users click the ad) is active, the ad or the ad activity will be displayed after switching back to the app. I would prefer that the app is displayed (i.e. the main activity is at the top of the activity stack) since it looked confusing to the users to see the ad first.

我试图捕获所有活动回调(例如onStart(),onResume()...),但是显然,在这种情况下,应用程序永远不会成为前台。由于广告活动是通过调用interstitialAd.show()开始的,所以我所知的管理活动堆栈的技巧也无济于事。

I tried to trap all the activity callbacks (such as onStart(), onResume() ...), but apparently the app will never become foreground in this use case. Since the ad activity is started by calling interstitialAd.show(), the tricks I know on managing the activity stack does not help, either.

有人知道如何自动进行吗?关闭广告并将应用程序的主要活动返回顶部?

Does anyone know how to automatically close the ad and return the app main activity to the top?

谢谢。

推荐答案

如果有人正在寻找答案。如果用户在展示插页式广告时点击了主页按钮,这将阻止它在用户再次启动该应用程序时显示。

If anyone is looking for an answer to this. If the user hits the Home button while the interstitial ad is being shown, this prevents it from showing when the user launches the app again.

在您的AndroidMainifest.xml文件中添加:
android:noHistory = true
进入AdActivity活动

In your AndroidMainifest.xml file add: android:noHistory="true" to the AdActivity activity

就像这样:

<activity android:name="com.google.android.gms.ads.AdActivity"
   android:noHistory="true"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
</activity>

到目前为止,这似乎一直有效。

This seems to be working so far.

这篇关于如果用户单击Android主页按钮,如何自动关闭admob插页式广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆