AdMob:interstistial广告加载一次.ack

时间:2017-05-27 18:20:51

标签: android admob interstitial

我有一个应用程序,当您按下时,我会在某个屏幕上加载空间广告。在第一次尝试时,interstistialAd.isLoaded()成为现实,但每次都会出现错误。我不知道我在这里失踪了什么。 这是我的代码:

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();
    }
}

感谢!!!

1 个答案:

答案 0 :(得分:1)

每次展示interstitialAd.show();广告后再次interstitialAd.loadAd(adRequest);