Interstitial Ad

1. Basic requirements

  • Add ADX Android SDK to your project.

  • Use the Ad Unit ID issued for Interstitial Ad.

  • Before requesting an ad, SDK initialization must be done first.

    • SDK initialization should be called only once when the app launches and ad requests should be made after SDK initialization is complete.

2. Implementation

  1. Instantiate the InterstitialAd and the InterstitialListener, then add them to the layout or relevant component.

  2. Call loadAd() to load the ad.

  3. After the ad is loaded and the onAdLoaded() callback is received, check isLoaded() to see if an ad is available, then call show() to display the ad.

  4. When the ad is no longer needed, call InterstitialAd’s destroy() method in onDestroy() to remove the ad.

public class InterstitialActivity extends AppCompatActivity {
    private com.adxcorp.ads.InterstitialAd interstitialAd;
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        interstitialAd = new InterstitialAd(this, "<INTERSTITIAL_AD_UNIT_ID>");
        interstitialAd.setInterstitialListener(new InterstitialAd.InterstitialListener() {
            @Override
            public void onAdLoaded() {
            }

            @Override
            public void onAdError(int errorCode) {
            }

            @Override
            public void onAdClicked() {
            }

            @Override
            public void onAdImpression() {
            }

            @Override
            public void onAdClosed() {
            }

            @Override
            public void onAdFailedToShow() {
            }
        });
        
        interstitialAd.loadAd();
    }
    
    void show() {
        if (interstitialAd != null && interstitialAd.isLoaded()) {
            interstitialAd.show();
        }
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
    
        if (interstitialAd != null) {
            interstitialAd.destroy();
            interstitialAd = null;
        }
    }
}

3. Callback

You can set the InterstitialAd’s InterstitialListener to receive specific events. Implement it as needed.

interstitialAd.setInterstitialListener(new InterstitialAd.InterstitialListener() {
    @Override
    public void onAdLoaded() {
    }

    @Override
    public void onAdError(int errorCode) {
    }

    @Override
    public void onAdClicked() {
    }

    @Override
    public void onAdImpression() {
    }

    @Override
    public void onAdClosed() {
    }

    @Override
    public void onAdFailedToShow() {
    }
});

4. Ad Revenue (OnPaidEvent)

  • You can receive the estimated ad revenue while an ad impression occurs.

  • Manually set values during mediation setup and actual values may be mixed, so it is recommended to treat this as an estimate.

  • The currency unit of eCPM is USD.

  • As shown in the example below, use OnPaidEvent to check the estimated eCPM value.

  • You can link ad revenue data with your MMP. For details, please refer to the SDK integration guides below:

interstitialAd.setOnPaidEventListener(new OnPaidEventListener() {
    @Override
    public void onPaidEvent(double ecpm) {
        /// Firebase Analytics Example
        double revenue = ecpm / 1000;

        mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
        Bundle params = new Bundle();
        params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "AD(X)");
        params.putString(FirebaseAnalytics.Param.AD_FORMAT, "InterstitialAd");
        params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, "ADX Interstitial Ad");
        params.putDouble(FirebaseAnalytics.Param.VALUE, revenue);
        params.putString(FirebaseAnalytics.Param.CURRENCY, "USD");
        mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params);
        
        // AppsFlyer Example
        double revenue = ecpm / 1000;

        Map<String, String> customParams = new HashMap<>();
        customParams.put(Scheme.AD_TYPE, "InterstitialAd");
        customParams.put("ad_unit_name", "ADX Interstitial Ad");

        AppsFlyerAdRevenue.logAdRevenue(
              "AD(X)",
              MediationNetwork.customMediation,
              Currency.getInstance(Locale.US),
              revenue,
              customParams
        );
    }
});

Last updated

Was this helpful?