Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

java - Ads are loading, but not showing?

My interstitial ads are successfully loading, but when I call .show() on them, they don't show up.

I have followed these directions, and the ads load successfully, but don't show when I call mInterstitialAd.show();:

In onCreate():

 mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId("My ID");

    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            requestNewInterstitial();
            beginPlayingGame();
        }
    });
        requestNewInterstitial();

requestNewInterstitial():

  private void requestNewInterstitial() {
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice("Phone's ID")
                .build();

        mInterstitialAd.loadAd(adRequest);
    }

HERE IS THE PROBLEM:

 public void tryAgain(View v) {
        if (mInterstitialAd.isLoaded()) {

            mInterstitialAd.show();
            Log.v(TAG, "LOADED in Game Over!");

        }
       else {
            beginPlayingGame();
        }

        beginPlayingGame();
    }

I get the log saying it is loaded in my log cat, but the ad doesn't actually show! Why is it loading, but not showing?

P.S. I think I actually got it to work once earlier, but it stopped working ever since then. What could be the problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It turns out that I just had to remove the extra method call after the else. For example,

public void tryAgain(View v) {
        if (mInterstitialAd.isLoaded()) {

            mInterstitialAd.show();
            Log.v(TAG, "LOADED in Game Over!");

        }
       else {
            beginPlayingGame();
        }

        beginPlayingGame();
    }

should have just been

public void tryAgain(View v) {
        if (mInterstitialAd.isLoaded()) {

            mInterstitialAd.show();
            Log.v(TAG, "LOADED in Game Over!");

        }
       else {
            beginPlayingGame();
        }
    //NOTICE THERE Is NO EXTRA METHOD CALL OF **beginPlayingGame()**
      }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...