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?