多次显示插页式广告

Show interstitial ad more than once

请帮忙。插页式广告仅显示一次。我希望它能被更多人看到。

private void loadAds() {
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    interstitial = new InterstitialAd(this);
    AdRequest adRequest2 = new AdRequest.Builder().build(); //
    interstitial.setAdUnitId(getResources().getString(R.string.admob_interstitial));
    interstitial.setAdListener(new AdListener() {

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

        @Override
        public void onAdClosed() {
            super.onAdClosed();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            AdLoaded = true;
        }
    });

    interstitial.loadAd(adRequest2);
}

public void displayInterstitial() {
    if (adsCounter == 0) {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
        adsCounter = 0;
    } else {
        adsCounter += 2;
    }
}

显示插页式广告后,您需要再次调用 loadAd(adRequest) 才能加载新的插页式广告。

OnAdClosed() 对此

    @Override
          public void onAdClosed () 
          {
              AdRequest adRequest = new AdRequest.Builder()
                .build();
              interstitial.loadAd(adRequest);
          }

对我来说,我必须调用 .destroy 并创建新实例。

创建全局变量

private MoPubInterstitial interstitial;

将样板代码放在一个函数中:createInterstitialAd。

 private void createInterstitialAd(){

        // TODO: Replace this test id with your personal ad unit id
        interstitial = new MoPubInterstitial(getActivity(), "<#YOUR_AD_UNIT_ID#>");
        interstitial.setInterstitialAdListener(this);
        interstitial.load();

    }

然后在广告加载失败或加载完成后调用InterstitialAdListener方法(注意:在onCreateView)

interstitial.destroy();
   createInterstitialAd();