简体   繁体   中英

Android app crash when rotating using AdMob

Hey i recently add a ads banner to my app

and after i added it all works fine... Until I rotate the phone and then the app crash

I added the following code to my original app code: In my home fragment ,

On create view:
...
    mAdStatus = (TextView) v.findViewById(R.id.status);
    mAdView = (AdView) v.findViewById(R.id.ad);
    mAdView.setAdListener(new MyAdListener(mAdStatus));

    AdRequest adRequest = new AdRequest();
    adRequest.addKeyword("sporting goods");
    mAdView.loadAd(adRequest);
return v;

in the xml:

    <LinearLayout
android:id="@+id/ad_catalog_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView android:id="@+id/status"
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:layout_weight="1"
    android:text="" />
<com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    googleads:adSize="SMART_BANNER"
    googleads:adUnitId="@string/admob_id" />

should I call on destroy and do something?

Thanks for the help

Problem solved.

The problem was that I forgot to put the xml code in the layout-land xml too.

Thanks :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM