Loading an Interstitial Ad
To load an interstitial ad, instantiate a MaxInterstitialAd
object corresponding to your ad unit and call its loadAd()
method. Implement MaxAdListener
so that you are notified when your ad is ready and 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", this ) 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() } }
Showing an Interstitial Ad
To show an interstitial ad, call showAd()
on the MaxInterstitialAd
object that you created.
-
if ( interstitialAd.isReady() ) { interstitialAd.showAd(); }
-
if ( interstitialAd.isReady ) { interstitialAd.showAd() }
Lock Screen Ads
The AppLovin MAX SDK version 11.0.0 provides APIs with which you can display interstitial ads in the lock screen. Use cases for this integration include audio apps which, by their nature, appear on the lock screen already.
Loading a Lock Screen Ad
You load an interstitial ad to display on the lock screen in a similar way to how you would normally load an interstitial ad, as described above. The only differences are that you need to set an extra parameter for the MaxInterstitialAd
, and the Activity
you pass in must implement the LifecycleOwner
interface.
-
⋮ import androidx.lifecycle.LifecycleOwner; ⋮ 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 ⋮ }
-
⋮ import androidx.lifecycle.LifecycleOwner ⋮ 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", this ) interstitialAd.setExtraParameter( "container_view_ads", "true" ) interstitialAd.setListener( this ) // Load the first ad interstitialAd.loadAd() } // MAX Ad Listener ⋮ }
If your interstitial is in a scrollable context such as scrollviews, add the following code to enable scrollability touch interaction with AppLovin ads (this is supported only in Android SDK versions 11.10.2+):
-
AppLovinSdk.getInstance( context ).getSettings().interstitialAd.setExtraParameter( "enable_container_ad_click_for_scrollview", "true" );
-
AppLovinSdk.getInstance( context ).settings.interstitialAd.setExtraParameter( "enable_container_ad_click_for_scrollview", "true" )
Note: AppLovin cannot guarantee the click interaction of third-party network ads in this integration model.
Showing a Lock Screen Ad
To show the interstitial ad, call showAd(…)
with the ViewGroup
in the lock screen ad.
-
if ( interstitialAd.isReady() ) { interstitialAd.showAd( adContainerView, getLifecycle() ); }
-
if ( interstitialAd.isReady ) { interstitialAd.showAd( adContainerView, getLifecycle() ) }
To close an interstitial ad programmatically, remove the interstitial from the container view by calling removeAllViews()
.
Mediated Network Support
The networks that support this feature are AppLovin Bidding and AppLovin Exchange. If you want to be notified of additional adapter updates, subscribe to the AppLovin-MAX-SDK-Android GitHub repository.
Adding Custom Support to Adapters
To add support into a custom adapter or one of our 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) { ⋮ }