My application opens a Publisher InterstitialAd whenever you start but when a user closes it reopens. This process happens constantly and then you can't use application, can anyone help me?
public void getIntertitalAds(boolean isPortraitMode)
{
interstitial = new PublisherInterstitialAd(context);
if(isPortraitMode)
interstitial.setAdUnitId(tags.getAdUnitInterstitial());
else
interstitial.setAdUnitId(tags.getAdUnitInterstitialTablet());
AdListener adListener = new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
if(interstitial!=null)
interstitial.show();
}
@Override
public void onAdClosed() {
super.onAdClosed();
interstitial = null;
}
};
// Create ad request.
PublisherAdRequest adRequest = new PublisherAdRequest.Builder()
.build();
// Begin loading your interstitial.
interstitial.setAdListener(adListener);
interstitial.loadAd(adRequest);
}
NEVER call interstitial.show()
from AdListener#onAdLoaded()
. You have no control over when it will be called and it presents a really poor user experience. Instead call interstitial.show()
at a natural break point in your app.
There is no need to have separate AdUnitIds for portrait and landscape. Interstitials are the same regardless.
All the code in your getIntertitalAds()
(sic) method should be Activity#onCreate
I strongly suspect your problems stem from a combination of 1 and 3.