Jakub Mateusiak
Jakub Mateusiak

Reputation: 99

Application with admob, screen rotation issue

I'm working at small application, had almost everything done and worked nice until I added AdMob into. I have separated layout for portrait and landscape divided in two folders: layout and layout-land. Also the values used in that layouts are separated in same way. The problem is that after adding AdMob the screen stoped rotating at changing orientation. The stranges thing is that the screen in emulator,but not in device, can rotate from portrait to landscape only without turning back.

I added AdActivity into manifest with

    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"

and code for AdView is:

android:id="@+id/ad" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1.5" ads:adSize="SMART_BANNER" ads:adUnitId="ca-app-pub-8671233073481795/9448252969" ads:loadAdOnCreate="true" ads:testDevices="TEST_EMULATOR,TEST_DEVICE_ID_GOES_HERE"

which is included into layouts.

Correct me if im wrong but becouse of android:configChanges="keyboard|keyboardHidden|orientation statement the android isn't maintain changing orientation of its own? So I must handle it myself by override the method OnConfigurationChanged, and move all values and layouts from "...-land" folders into layout/values folders with unique name? I hope there is a better way to do this, and a way to store values and layouts for landscape orientation in diffrent folders.

Thank you in advance.

Changing the layout atributes for AdView doesn't helping, the screen is still turning from portrait to landscape but not vice versa

The problem is solved, it was some error with emulator, on device and in emulator on android 2.3+ everything works fine

Upvotes: 0

Views: 1113

Answers (1)

Morrison Chang
Morrison Chang

Reputation: 12121

Its only the AdMob's AdActivity that has the android:configChanges parameter. Probably for any full screen ads. For your Activities - handle it the way you want.

You also may want to use standard ad sizes as you appear to have a 0dp in your layout height. I would start with the suggested settings in the documentation of 'wrap_content' for both height and width and see if that changes anything.

Upvotes: 0

Related Questions