emboole
emboole

Reputation: 571

AdMob: interstistial ad loads just one time.ack

i have an application where i load interstistial ads on a certain screen when you press back. On the first attempt, interstistialAd.isLoaded() comes true, but then it comes false every other time. I don't get what i'm missing here. This is my code:

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  Bundle b = getIntent().getExtras();
  videoId = b.getString("videoId");
  setContentView(R.layout.youtube_player);

  //begin ads
  interstitialAd= new InterstitialAd(this);
  interstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
  AdRequest adRequest = new AdRequest.Builder().build();
  interstitialAd.loadAd(adRequest);

  adCounter++;
  //end ads

YouTubePlayerFragment youTubePlayerFragment =
    (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.youtube_fragment);
youTubePlayerFragment.initialize(ApiKey.YOUTUBE_API_KEY, this);

  //OnClick listener
  findViewById(R.id.backButton).setOnClickListener( new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          ShowAds();
          finish();
      }
  });

    @Override
public void onBackPressed() {
    ShowAds();

}

private void ShowAds() {

    if (interstitialAd.isLoaded() {
        interstitialAd.show();
        AdRequest adRequest = new AdRequest.Builder().build();
        interstitialAd.loadAd(adRequest);
        interstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                super.onAdClosed();
                finish();
            }
        });
    }else{
        super.onBackPressed();
    }
}

Thanks!!!

Upvotes: 0

Views: 123

Answers (1)

Simo
Simo

Reputation: 345

after every show interstitialAd.show(); request for ad again interstitialAd.loadAd(adRequest);.

Upvotes: 1

Related Questions