Interstitial Ad

Below are the steps to load and show an Interstitial ad using xGrowth SDK on your app

1

Create your AdRequestConfiguration

Java / Kotlin

Java
AdRequestConfiguration.Builder configuration = AdRequestConfiguration.Companion.builder(context, "Your_placement_name");
2

Call loadAd()

Provide listeners and build the loader, then call loadAd with your configuration.

Java
AdSterAdLoader.Companion.builder().withAdsListener(new MediationAdListener(){
    @Override
    public void onInterstitialAdLoaded(@NonNull MediationInterstitialAd ad) {
        super.onInterstitialAdLoaded(ad);
        //Show interstitial ad here
    }

    @Override
    public void onFailure(@NonNull AdError adError) {
        //Handle failure callback here
    }
}).withInterstitialAdEventsListener(new InterstitialAdEventsListener() {
    @Override
    public void onAdClicked() {
        //Handle ad click here
    }

    @Override
    public void onAdImpression() {
        //Handle ad impression here
    }

    @Override
    public void onAdOpened() {
        //Handle ad open here
    }

    @Override
    public void onAdClosed() {
        //Handle ad closed here
    }

    @Override
    public void onAdRevenuePaid(double revenue, @NotNull String adUnitId,@NotNull String network) {
        // Callback which provides revenue and the network which provided it
    }
}).build().loadAd(configuration.build());
3

Show the interstitial ad inside onInterstitialAdLoaded

Inside the onInterstitialAdLoaded callback method invoke showAd(activity) method of MediationInterstitialAd object to show xGrowth interstitial ad above any activity as shown below

Java
@Override
public void onInterstitialAdLoaded(@NonNull MediationInterstitialAd ad) {
     super.onInterstitialAdLoaded(ad);
     ad.showAd(getApplicationContext());
}
4

Important

circle-exclamation

Last updated