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.

4. Ad Revenue (OnPaidEvent)

Last updated

Was this helpful?