Interstitial Ads
Interstitial ads are full-screen or full-page ads that temporarily cover an app’s interface. They’re typically shown at natural pauses or transition points—such as after completing a level in a game or when navigating between major views.
The following sections show you how to load and then show an interstitial ad.
Loading an Interstitial Ad
The following code shows you how to attach listeners and load the first interstitial:
final String _interstitial_ad_unit_ID = Platform.isAndroid ? "«Android-ad-unit-ID»" : "«iOS-ad-unit-ID»";const int _maxExponentialRetryCount = 6;var _interstitialRetryAttempt = 0;
void initializeInterstitialAds() {
AppLovinMAX.setInterstitialListener(InterstitialListener( onAdLoadedCallback: (ad) { // Interstitial ad is ready to show. AppLovinMAX.isInterstitialReady(_interstitial_ad_unit_ID) now returns 'true'. print('Interstitial ad loaded from ' + ad.networkName);
// Reset retry attempt _interstitialRetryAttempt = 0; }, onAdLoadFailedCallback: (adUnitId, error) { // Interstitial ad failed to load. // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds). _interstitialRetryAttempt = _interstitialRetryAttempt + 1; if (_interstitialRetryAttempt > _maxExponentialRetryCount) return; int retryDelay = pow(2, min(_maxExponentialRetryCount, _interstitialRetryAttempt)).toInt();
print('Interstitial ad failed to load with code ' + error.code.toString() + ' - retrying in ' + retryDelay.toString() + 's');
Future.delayed(Duration(milliseconds: retryDelay * 1000), () { AppLovinMAX.loadInterstitial(_interstitial_ad_unit_ID); }); }, onAdDisplayedCallback: (ad) { ⋮ }, onAdDisplayFailedCallback: (ad, error) { ⋮ }, onAdClickedCallback: (ad) { ⋮ }, onAdHiddenCallback: (ad) { ⋮ }, ));
// Load the first interstitial. AppLovinMAX.loadInterstitial(_interstitial_ad_unit_ID);}
Showing an Interstitial Ad
To show an interstitial ad, call showInterstitial()
:
bool isReady = (await AppLovinMAX.isInterstitialReady(_interstitial_ad_unit_ID))!;if (isReady) { AppLovinMAX.showInterstitial(_interstitial_ad_unit_ID);}