2

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);
}
nss
  • 121
  • 2
  • 11

1 Answers1

1
  1. 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.

  2. There is no need to have separate AdUnitIds for portrait and landscape. Interstitials are the same regardless.

  3. 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.

William
  • 20,150
  • 8
  • 49
  • 91
  • What if I want to show my interstitial at application startup, this is, as soon as it is ready? – joao2fast4u Nov 19 '14 at 17:08
  • If you use #onAdLoaded to initiate the display then you will be interupting the user mid task. So I would argue that showing on app start up is not ideal. However, if you have some user initiated step post startup that you can use to display an ad (if you have already loaded one) then it is much better. – William Nov 20 '14 at 18:15