Search code examples
androidadmobloadingadsinterstitial

Android - new Interstitial Ad not Loading (Admob)


I'm trying to test interstitial ads in my app, and the first interstitial works fine. However, when I request a new, second ad using mInterstitialAd.loadAd(new AdRequest.Builder().build()), onAdLoaded() is never called.

My AdListener, if it helps:

mInterstitialAd.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded() {
            adIsLoaded = true;
        }

        @Override
        public void onAdOpened() {
            mInterstitialAd.loadAd(new AdRequest.Builder().build());

            adIsLoaded = false;
            adIsTimeReady = false;

        }

        @Override
        public void onAdClosed() {
            new CountDownTimer(adInterval, adInterval) { //timer to only show new ad if atleast some interval of time has passed

                public void onTick(long millisUntilFinished) {}

                public void onFinish() {
                    adIsTimeReady = true;
                }
            }.start();

I am using an emulator, so the ads are test ads. Is there only one test ad or something, and a new ad can't be requested?

Thanks, Stephen


Solution

  • It seems the issue was that I was trying to load a new ad before the previous one was closed. Below I simply deleted the onAdOpened method and moved its contents to the onAdClosed method.

    mInterstitialAd.setAdListener(new AdListener() {
    
            @Override
            public void onAdLoaded() {
                adIsLoaded = true;
            }
    
            @Override
            public void onAdClosed() {
    
                mInterstitialAd.loadAd(new AdRequest.Builder().build());
    
                adIsLoaded = false;
                adIsTimeReady = false;
    
                new CountDownTimer(adInterval, adInterval) {
    
                    public void onTick(long adInterval) {}
    
                    public void onFinish() {
                        adIsTimeReady = true;
                    }
                }.start();
            }
        });