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.
To load an interstitial ad, first instantiate a MaxInterstitialAd object corresponding to your ad unit.
Then call that object’s loadAd() method.
Implement MaxAdListener so that you are notified when your ad is ready (you are also notified of other ad-related events).
public class ExampleActivity extends Activity
implements MaxAdListener
{
private MaxInterstitialAd interstitialAd;
private int retryAttempt;
void createInterstitialAd()
{
interstitialAd = new MaxInterstitialAd( "«ad-unit-ID»", this );
interstitialAd.setListener( this );
// Load the first ad
interstitialAd.loadAd();
}
// MAX Ad Listener
@Override
public void onAdLoaded(final MaxAd maxAd)
{
// Interstitial ad is ready to be shown. interstitialAd.isReady() will now return 'true'
// Reset retry attempt
retryAttempt = 0;
}
@Override
public void onAdLoadFailed(final String adUnitId, final MaxError 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)
retryAttempt++;
long delayMillis = TimeUnit.SECONDS.toMillis( (long) Math.pow( 2, Math.min( 6, retryAttempt ) ) );
new Handler().postDelayed( new Runnable()
{
@Override
public void run()
{
interstitialAd.loadAd();
}
}, delayMillis );
}
@Override
public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error)
{
// Interstitial ad failed to display. AppLovin recommends that you load the next ad.
interstitialAd.loadAd();
}
@Override
public void onAdDisplayed(final MaxAd maxAd) {}
@Override
public void onAdClicked(final MaxAd maxAd) {}
@Override
public void onAdHidden(final MaxAd maxAd)
{
// Interstitial ad is hidden. Pre-load the next ad
interstitialAd.loadAd();
}
}class ExampleActivity : Activity(), MaxAdListener
{
private lateinit var interstitialAd: MaxInterstitialAd
private var retryAttempt = 0.0
fun createInterstitialAd()
{
interstitialAd = MaxInterstitialAd( "«ad-unit-ID»", applicationContext )
interstitialAd.setListener( this )
// Load the first ad
interstitialAd.loadAd()
}
// MAX Ad Listener
override fun onAdLoaded(maxAd: MaxAd)
{
// Interstitial ad is ready to be shown. interstitialAd.isReady() will now return 'true'
// Reset retry attempt
retryAttempt = 0.0
}
override fun onAdLoadFailed(adUnitId: String?, error: MaxError?)
{
// Interstitial ad failed to load
// AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt++
val delayMillis = TimeUnit.SECONDS.toMillis( Math.pow( 2.0, Math.min( 6.0, retryAttempt ) ).toLong() )
Handler().postDelayed( { interstitialAd.loadAd() }, delayMillis )
}
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?)
{
// Interstitial ad failed to display. AppLovin recommends that you load the next ad.
interstitialAd.loadAd()
}
override fun onAdDisplayed(maxAd: MaxAd) {}
override fun onAdClicked(maxAd: MaxAd) {}
override fun onAdHidden(maxAd: MaxAd)
{
// Interstitial ad is hidden. Pre-load the next ad
interstitialAd.loadAd()
}
}Best practices: Displaying interstitial ads
To show an interstitial ad, call showAd( this ) on the MaxInterstitialAd object that you created.
if ( interstitialAd.isReady() )
{
// `this` is the activity that will be used to show the ad
interstitialAd.showAd( this );
}if ( interstitialAd.isReady )
{
// `this` is the activity that will be used to show the ad
interstitialAd.showAd(this)
}The AppLovin MAX SDK provides APIs with which you can display interstitial ads in the lock screen. Use cases for this integration include audio apps, which typically appear on the lock screen.
When you load an interstitial ad to display on the lock screen, you need to set an extra parameter for the MaxInterstitialAd, and the Activity you pass in must implement the LifecycleOwner interface.
⋮
⋮
public class ExampleActivity extends Activity
implements MaxAdListener, LifecycleOwner
{
private FrameLayout adContainerView;
private MaxInterstitialAd interstitialAd;
private int retryAttempt;
void createInterstitialAd()
{
interstitialAd = new MaxInterstitialAd( "«ad-unit-ID»", this );
interstitialAd.setExtraParameter( "container_view_ads", "true" );
interstitialAd.setListener( this );
// Load the first ad
interstitialAd.loadAd();
}
// MAX Ad Listener
⋮
}⋮
⋮
class ExampleActivity : Activity(), MaxAdListener, LifecycleOwner
{
private lateinit var adContainerView: FrameLayout
private lateinit var interstitialAd: MaxInterstitialAd
private var retryAttempt = 0.0
fun createInterstitialAd()
{
interstitialAd = MaxInterstitialAd( "«ad-unit-ID»", applicationContext )
interstitialAd.setExtraParameter( "container_view_ads", "true" )
interstitialAd.setListener( this )
// Load the first ad
interstitialAd.loadAd()
}
// MAX Ad Listener
⋮
}To show the lock screen interstitial ad, call showAd(…) with the ViewGroup in the ad.
if ( interstitialAd.isReady() )
{
// `this` is the activity that will be used to show the ad
interstitialAd.showAd( adContainerView, getLifecycle(), this );
}if ( interstitialAd.isReady )
{
// `this` is the activity that will be used to show the ad
interstitialAd.showAd( adContainerView, getLifecycle(), this )
}The networks that support this feature are Axon’s Ads Manager and AppLovin Exchange.
To add support into a custom adapter or one of AppLovin’s open source adapters, override the following showInterstitialAd(…) method.
@Override
public void showInterstitialAd(final MaxAdapterResponseParameters parameters,
final ViewGroup containerView,
final Lifecycle lifecycle,
final Activity activity,
final MaxInterstitialAdapterListener listener)
{
⋮
}