I am running interstitial ads in my app, but I am not sure how to preload them so they appear to the user to be instantaneous. Often it can take up to 10 seconds, and the user has already moved on to different areas of the app, it's very annoying.
This is the relevant code from the app:
private void launchInterstitial() {
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("ca-app-pub-xxxxxxxxxxxxxxxx");
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
showAdInter();
}
@Override
public void onAdFailedToLoad(int errorCode) {
String message = String.format("onAdFailedToLoad (*a)", getErrorReason(errorCode));
}
@Override
public void onAdClosed() {
if (exitApp) {
finish();
}
}
});
}
private void showAdInter() {
if (interstitialAd.isLoaded()){
interstitialAd.show();
} else {
Log.d("","Interstitial ad failed to load");
}
}
public void loadInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("Fxxxxxxxxxxxxxxxxxxxxx")
.build();
interstitialAd.loadAd(adRequest);
}
I have tried calling launchInterstitial() and loadInterstitial() when the activity launches and then call showAdInter() when I want the ad to appear, but it doesn't work that way.
Anyone have any ideas?