Orientation problem with Admob full screen interstitial

3,235 views
Skip to first unread message

TL

unread,
Nov 16, 2016, 3:51:16 PM11/16/16
to Google Mobile Ads SDK Developers
I'm having a problem with displaying full screen interstitial ads in my game.  The game support fullSensor device orientation.  This is my activity:

<activity
android:name="com.mydomain.mygame.android.AndroidLauncher"
android:label="My Game"
android:screenOrientation="fullSensor"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

I have also included an activity for AdMob:

<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />

The ads are loading and display fine, but the problem is that they are not respecting the device orientation post start up.  E.g. if I start the game with the device upright, then show an ad, it displays correctly in portrait orientation.  However if I then tilt the device (my game updates to landscape orientation), and then show an ad, then the ad appears in portrait orientation still (on its side).  Subsequent ads all appear incorrectly in the original orientation of the device at application start up.

The same is true if I start in landscape orientation, then I see an add in landscape orientation correctly, however tilting the device to portrait mode, the ads still continue to appear in landscape mode...

In onCreate(), I am calling:

interstitialAd = new InterstitialAd(activity);
interstitialAd.setAdUnitId(GameConfig.ADMOB_UNIT_ID);
requestNewInterstitial();

with:

private void requestNewInterstitial() {
AdRequest.Builder builder =
new AdRequest.Builder();
builder.addTestDevice("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

AdRequest adRequest = builder.build();
interstitialAd.loadAd(adRequest);
}

And then I am showing the ad with the following code:

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (interstitialAd.isLoaded()) {
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
Gdx.app.postRunnable(then);
requestNewInterstitial();
}
});

interstitialAd.show();
} else {
Gdx.app.postRunnable(then);
}
}
});

What am I doing wrong here? can I invalidate the ad activity somehow to force it to reload in the correct orientation?

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Nov 16, 2016, 4:12:34 PM11/16/16
to Google Mobile Ads SDK Developers
Hi there,

Can you try reproduce this issue with our sample apps? Also, make sure that you are using the latest Google Play Services version. I have just now tested with our sample apps and was unable to reproduce this issue.

Also, note that we do not support libgdx, which might be the cause of the issue. If so, I would suggest you to contact the author directly for support.

Thanks,
Arjun Busani
Mobile Ads SDK Team

TL

unread,
Nov 16, 2016, 4:33:23 PM11/16/16
to Google Mobile Ads SDK Developers
Hi Arjun,

Thanks for the quick reply.  I tried the sample app you linked and it does not display the same problem.  I'll try to see if I can find a difference between that and my game setup.

TL

unread,
Nov 16, 2016, 4:49:46 PM11/16/16
to Google Mobile Ads SDK Developers
Hi Arjun,

I've managed to track the problem down to this bit of the manifest:

android:configChanges="keyboard|keyboardHidden|orientation|screenSize">

I can reproduce the problem now with your sample app by changing your manifest file to this:

<activity
android:name=".MyActivity"
android:label="@string/app_name"
    android:screenOrientation="fullSensor"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

I guess that makes sense, because your sample app is destroying and recreating the activity when you rotate the device - actually you can see in your sample app that the timer restarts on rotation.

On Wednesday, November 16, 2016 at 9:12:34 PM UTC, Veer Arjun Busani(Mobile Ads SDK Team) wrote:

TL

unread,
Nov 16, 2016, 6:18:21 PM11/16/16
to Google Mobile Ads SDK Developers
Sorry, just to be clear, this is still a problem.  The sample app restarts the activity on rotation of the device, which is not a viable solution for a game.  There needs to be a way to have the AdMob interstitial update to the new orientation without having to completely restart the main game activity.  Any ideas?

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Nov 17, 2016, 10:02:31 AM11/17/16
to Google Mobile Ads SDK Developers
Hi there,

If your presenting Activity is also handling configChanges, then you need to programmatically make the new AdRequest when the device orientation change occurs. From your Activity, you can do that following by overriding the onConfigurationChanged callback and making a new AdRequest - 

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE || newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        AdRequest adRequest = new AdRequest.Builder()
                                    .build();
        mInterstitialAd.loadAd(adRequest);
    }
}

Thanks,
Arjun Busani
Mobile Ads SDK Team

TL

unread,
Nov 17, 2016, 1:23:13 PM11/17/16
to Google Mobile Ads SDK Developers
Hi Arjun,

This does not solve the problem.  I have added that code to the sample app and the problem persists.  Start the sample app in portrait orientation, then turn on its side, ALL subsequent ads appear incorrectly in portrait mode (i.e. the original orientation on start up).  

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Nov 17, 2016, 1:45:49 PM11/17/16
to Google Mobile Ads SDK Developers
Hi there,

Here is a sample app that would solve your issue.

Thanks,
Arjun Busani
Mobile Ads SDK Team

TL

unread,
Nov 23, 2016, 4:44:36 PM11/23/16
to Google Mobile Ads SDK Developers
Thanks Arjun,

I have it working nicely now! 

I think the key bit of code was to create a new instance of the InterstitialAd on orientation change. I also had to run it on the UI thread.

Thanks for taking the time :-)

Nawshad Hamid

unread,
Mar 3, 2018, 12:16:51 AM3/3/18
to Google Mobile Ads SDK Developers
please do not use any properties in Android Manifest files AdActivity.

please remove this line from AdActivity in Manifest file

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

Just simply add this following line to Android Manifest file.

    
        <activity android:name="com.google.android.gms.ads.AdActivity" />

Reply all
Reply to author
Forward
0 new messages