How to show Interstitial ad correctly in this case?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 14:44:20

From your code you're giving request to load ad then when your ad is loaded then you show that ad.

There's always a delay in loading ads so my suggestion is load your ad previously is background and not show that ad. whenever you want to show ad only check is your interstitial is ready to show, if yes show.

Call createInterstitial() at once in background and after that whenever you want to show interstitial Ad, call showInterstitial().

public void crateInterstitial(){

    interstitialAd = new InterstitialAd(this.activity);
    interstitialAd.setAdUnitId(AD_UNIT_ID_INTERSTITIAL);
    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            // not call show interstitial ad from here            
        }

        @Override
        public void onAdClosed() {
              loadInterstitial(); 
         }
      });
    loadInterstitial();
}

public void loadInterstitial(){

     AdRequest interstitialRequest = new AdRequest.Builder().build();
     interstitialAd.loadAd(interstitialRequest);
}

public void showInterstitial(){
     if (interstitialAd.isLoaded()) 
          interstitialAd.show();                          
     else 
         loadInterstitial();                                                      
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!