1

I'm implementing Admob interstitial ads in a button. But it take 3-4 seconds to load the ads, user wrongly click button again and app get crush. How to preload interstitial ads or load instantly when press the button. Here is my code.

img_ply.setOnClickListener(new View.OnClickListener() {

   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub


    mAdView = (AdView) findViewById(R.id.adView);
    mAdView.loadAd(new AdRequest.Builder().build());

    mInterstitial.setAdUnitId(getResources().getString(R.string.admob_intertestial_id));
    mInterstitial.loadAd(new AdRequest.Builder().build());

    mInterstitial.setAdListener(new AdListener() {
     @Override
     public void onAdLoaded() {
      // TODO Auto-generated method stub
      super.onAdLoaded();
      if (mInterstitial.isLoaded()) {
       mInterstitial.show();
       mInterstitial.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
         super.onAdClosed();
         finish();

         Intent inttv = new Intent(SingleChannelActivity.this, TvPlay.class);
         inttv.putExtra("url", ChannelUrl);
         startActivity(inttv);
        }
       });
      }else{
       super.onAdLoaded();


      }
     }
    });
   }
  });
Lu Maw
  • 53
  • 9

1 Answers1

2

You should put Interstitial load method into onCreate() function of view, not in onClick event of the button ! So, there will be only mInterstitial.show() method in onClick() event. You must load the inters ads onCreate() and inters ads will be ready whenever you need..

Mucahid Uslu
  • 367
  • 3
  • 11
  • Appear interstitial ads, proceed to new activity and after clicked Back Button, I cannot click the ads implemented button again... any suggestion? – Lu Maw Feb 28 '17 at 13:01
  • You must implement onResume() method at first activity, and put code inters.load and set event listener there also.. you can look here more solutions.. http://stackoverflow.com/questions/5545217/back-button-and-refreshing-previous-activity – Mucahid Uslu Mar 01 '17 at 05:40