After click AdMob ads, I cannot return to my Android app by back button

不羁的心 提交于 2019-12-24 04:51:50

问题


I add AdMob in my application using the following code.

<?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >
<com.google.ads.AdView 
    android:id="@+id/adview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER" 
    ads:adUnitId="ca-app-pub-*************************"
    ads:loadAdOnCreate="true"
    ads:testDevices="********************"
    />
 <TabHost
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        >

        <TabWidget
            android:id="@android:id/tabs"
            android:textSize="12sp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        </FrameLayout>
    </LinearLayout>
 </TabHost>
</LinearLayout>

The ad is displayed on my phone. However, it does not return to my app when I touch "Back" button. Instead, it returns to my phone web pages previously viewed. Any suggestions are welcome.


回答1:


Please try this in your manifest

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

Especially, 'noHistory'. It works for me.




回答2:


To me this is expected behaviour, as I have had this happen to me occasionally. Once the user clicks on the ad, the back button is tied to whatever application is then opened. It's normally either Google Play or your phone's browser.

In Google Play clicking back will typically take you straight back to your app. However, in your browser, pressing back will either take you back to your last previously viewed pages (like pressing back in a browser), or if there isn't any, then back to your app.

Once the user clicks the ad, control of the back button is out of your hands, really.




回答3:


When clicking the admob ad, the Internet browser app on the whole is launched and not just one activity that shows a webpage. That's the reason your app sits below the Internet browse in the stack just as badgerati said.. To throw more highlight to the matter, when you launch gallery application to view the image (from your app) only the Vies Image activity fires up and not the whole galary app hence when you click back you return to your app.. But unluckily the things are not same with browsers




回答4:


It sounds like you may have misconfigured one of the Application or Activity attributes in your AndroidManifest. Something like launchMode, noHistory, allowTaskReparenting, etc.

Post your AndroidManifest.




回答5:


That happened to me when I had 'Don't save activities' checked in Settings|Developers Options. If unchecked (as it normally should be) everything works fine.



来源:https://stackoverflow.com/questions/20663480/after-click-admob-ads-i-cannot-return-to-my-android-app-by-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!