1

I am working on an android application and i have tried to implement Interstitial Ad but it takes 3 4 seconds to load and it causing accidental clicks on my app Please help how to pre load my add so that it appears instantly on the next screen.

My code is here under:

public class AboutActivity extends AppCompatActivity {

 private AdView mAdView;
 private InterstitialAd interstitial;

 @Override
 protected void onCreate(Bundle savedInstanceState) {

    interstitial = new InterstitialAd(AboutActivity.this);
    interstitial = new InterstitialAd(getApplicationContext());
    interstitial.setAdUnitId("ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXX");
    AdRequest adRequest1 = new AdRequest.Builder().build();
    interstitial.loadAd(adRequest1);
    interstitial.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded() {
            if(interstitial.isLoaded()) {
                interstitial.show();
            }

        }
    });

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);

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

  }
}
Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65
Asad Arman
  • 11
  • 2

1 Answers1

0
interstitial.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded() {
             //Remove show() code from here

        }
    });

Don't call show() method on your interstitial Ad inside onAdLoaded() method. Make a method to show interstitial Ad and call that method when you want to show

public void showIntersitial(){

    if(interstitial.isLoaded()) {

        interstitial.show();

    }else{

       // Not loaded make a request to load
       AdRequest adRequest1 = new AdRequest.Builder().build();
       interstitial.loadAd(adRequest1);
    }

}

You also need to add a listener to your Ad and make a new Ad request when you close your Interstitial Ad.

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65