I'm having a strange issue where my AdMob AdView banner seems to disappear when the device is rotated. I initially solved this by setting android:configChanges="orientation|keyboardHidden|screenSize"
on the activity in the manifest file. This worked fine until I made a second layout to use for landscape on tablets. The screenSize
flag means that the phone will not dynamically show the landscape/portrait layout, it instead uses the same layout for the original orientation. Is there anyway that I can persist the AdView banners when rotating the screen without using this flag?
My xml is as follows
<com.google.android.gms.ads.doubleclick.PublisherAdView
android:id="@+id/ad_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
ads:adSize="MEDIUM_RECTANGLE"
ads:adUnitId="@string/test_id"/>
The banner itself is loaded when the activity has received a response from the API for a network call, which is made when the fragment has been added to the activity.
@Override
protected void onResume() {
super.onResume();
if (mAdView != null) {
mAdView.resume();
}
}
@Override
protected void onPause() {
if (mAdView != null) {
mAdView.pause();
}
super.onPause();
}
@Override
protected void onDestroy() {
if (mAdView != null) {
mAdView.destroy();
}
super.onDestroy();
}
private void onNetworkCallSuccessful() {
mAdView = (PublisherAdView) findViewById(R.id.ad_view);
setupAdMobListener();
Bundle bundle = new Bundle();
bundle.putString("testKey","testValue");
mAdView.loadAd(new PublisherAdRequest.Builder().addNetworkExtras(new AdMobExtras(bundle)).build();
}
Any advice would be greatly appreciated.