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.

有帮助吗?

解决方案

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.

其他提示

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.

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

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.

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top