Edward D. Baum
Edward D. Baum

Reputation: 63

Why does my Android Activity close when AdMob loads an ad?

I've been putting AdMob ads in an otherwise working Android app, following the instructions here. The app has 2 activities. One of them is only reachable from the first. I'm currently adding ads to this second activity. I've tried both creating an AdView programmatically in the onCreate method and adding appropriate code to the XML layout file for the Activity. In both cases the activity will exit the second Activity and go to the first as if the back button had been pressed as soon as it recieves an ad (or at least some ad data over the network). If I change the code so as to not make an add request (even if I add the ad programatically but just don't to call loadAd), or if I turn off my netwrok access then I don't see any ads, but my Activity doesn't exit either. What could be causing this?

I've gone through all the (I believe out of date) steps here, but that doesn't help. Just to be clear in case I did something wrong, I have:

The next thing I think you'll want to know if you try to help me is what LogCat says. Not much:

09-02 14:33:34.861: I/Ads(12839): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"msid":"com.Package.Name","hl":"en","bas_off":0,"simulator":1,"preqs":0,"slotname":"a150cbaa53d9d3d","js":"afma-sdk-a-v6.2.1","isu":"B3EEABB8EE11C2BE770B684D95219ECB","u_audio":4,"cap":"m,a","cipa":0,"u_sd":1.5,"net":"ed","u_h":533,"oar":0,"session_id":"4834854664722735718","seq_num":"1","app_name":"1.android.com.Package.Name","bas_on":0,"kw":[],"u_w":320,"gnt":3,"adtest":"on","format":"320x50_mb","carrier":"310260","ad_pos":{"visible":0,"width":0,"height":0,"x":0,"y":0},"ptime":0});</script></head><body></body></html>
09-02 14:33:35.111: D/dalvikvm(12839): GC freed 8784 objects / 437720 bytes in 64ms
09-02 14:33:37.101: I/Ads(12839): Received ad url: <url: "http://googleads.g.doubleclick.net:80/mads/gma?msid=com.Package.Name&hl=en&bas_off=0&preqs=0&js=afma-sdk-a-v6.2.1&isu=B3EEABB8EE11C2BE770B684D95219ECB&u_audio=4&cap=m%2Ca&cipa=0&u_sd=1.5&net=ed&u_h=533&oar=0&session_id=4834854664722735718&seq_num=1&app_name=1.android.com.Package.Name&bas_on=0&kw&u_w=320&gnt=3&adtest=on&format=320x50_mb&carrier=310260&ptime=0&u_so=p&output=html&region=mobile_app&u_tz=0&client_sdk=1&ex=1&slotname=a14e8f77524dde8&kw_type=broad&gsb=3g&caps=interactiveVideo_th_autoplay_mediation_sdkAdmobApiForAds_di&jsv=41" type: "admob" afmaNotifyDt: "null" useWebViewLoadUrl: "false">
09-02 14:33:37.111: I/Ads(12839): Request scenario: Online server request.
09-02 14:33:38.061: I/jdwp(12861): received file descriptor 10 from ADB
09-02 14:33:38.091: D/ddm-heap(12861): Got feature list request

EDIT: I don't think it will be very useful, but at the request of suleman khan here is my current XML

<com.google.ads.AdView android:layout_width="wrap_content"
    android:layout_height="wrap_content" ads:adUnitId="a150cbaa53d9d3d"
    ads:adSize="SMART_BANNER" android:id="@+id/adView" ads:refreshInterval="60" 
    ads:testDevices="TEST_EMULATOR"
    ads:loadAdOnCreate="true" />

I"ve tried many variations of this, with no success.

Upvotes: 2

Views: 847

Answers (2)

Mohan
Mohan

Reputation: 661

above code will work, and you can remove these tags also

    android:minSdkVersion="8"
    android:targetSdkVersion="8"

Upvotes: 0

user1143305
user1143305

Reputation:

Place this code in your xml:

<com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_alignParentTop="true"
                         android:layout_height="wrap_content"
                         ads:adUnitId="@string/my_publisher_id"
                         ads:adSize="SMART_BANNER"
                         ads:loadAdOnCreate="true"/>

Hope you have added your publisher id.

Place this after your activity in Manifest file:

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

As you said that you have added jar file in libs in your project and hope you have also configured it in your buildpath.

Hope this helps.

Upvotes: 1

Related Questions