1
I’m trying to implement an interstitial ad, and I would like it to be loaded before, in the app it’s happening to load along with the action which causes delay and makes the ad appear well after. I want to make the ad appear right after pressing "add" as shown in the image below:
The code below shows how it was implemented:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-8920922366585510/4181958830");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
if (requestCode == ADD_PACK) {
if (resultCode == Activity.RESULT_CANCELED) {
if (data != null) {
final String validationError = data.getStringExtra("validation_error");
if (validationError != null) {
if (BuildConfig.DEBUG) {
//validation error should be shown to developer only, not users.
MessageDialogFragment.newInstance(R.string.title_validation_error, validationError).show(getSupportFragmentManager(), "validation error");
}
Log.e(TAG, "Validation failed:" + validationError);
}
} else {
new StickerPackNotAddedMessageFragment().show(getSupportFragmentManager(), "sticker_pack_not_added");
}
}
}
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
mInterstitialAd.show();
}
});
}
I’ve tried to place the charging call before those codes but I can’t get it to charge before.
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-8920922366585510/4181958830");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
The application is an open source github, the link is just below if you want to download to see the full code and help: DOWNLOAD FULL CODE