---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://boost.yandex.ru/doc/en/ad-monetization/dev/android/interstitial.md
  - https://boost.yandex.ru/doc/ru/ad-monetization/dev/android/interstitial.md
  - href: en/ad-monetization/dev/android/interstitial.md
    type: text/markdown
    title: Markdown version
  - href: llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://boost.yandex.ru/doc/en/llms.txt

# Interstitial ads

<!-- source: en/ad-monetization/dev/_includes/interstitial.md -->
Interstitial advertising is a full-screen ad format embedded within the app content during natural pauses, such as transitioning between game levels or completing a target action.
<!-- endsource: en/ad-monetization/dev/_includes/interstitial.md -->

When an app displays an interstitial ad, the user can either click through to the advertiser's site or close the ad and return to the app.

During interstitial ad impressions, the user's attention is fully focused on the ad, which results in a higher cost for such impressions.

{% cut "Appearance" %}

<img src="https://yastatic.net/s3/doc-binary/src/docs/support/mobile-ads/en/monetization/_images/interstitial-en-ex.png" width="200">


{% endcut %}

This guide will show how to integrate interstitial ads into Android apps. Besides code samples and instructions, it contains format-specific recommendations and links to additional resources.


## Prerequisite {#pre}

<!-- source: en/ad-monetization/dev/_includes/pre-android.md -->
1. Follow the SDK integration steps described under [Quick start](https://boost.yandex.ru/doc/en/ad-monetization/dev/android/quick-start.md).
2. First, you need to [initialize](https://boost.yandex.ru/doc/en/ad-monetization/dev/android/quick-start.md#init) the advertising SDK.
3. Make sure you have the [latest Yandex Mobile Ads SDK version](https://boost.yandex.ru/doc/en/ad-monetization/dev/android/changelog-android.md). If you're using mediation, update to the most recent [single build version](https://boost.yandex.ru/doc/en/ad-monetization/dev/android/changelog-android.md).
<!-- endsource: en/ad-monetization/dev/_includes/pre-android.md -->

## Implementation {#implement}

Key steps for integrating interstitial ads:

* Create and configure the `InterstitialAdLoader` ad loader.
* Register the listener for ad load callback methods: `InterstitialAdLoadListener`.
* Load the ad.
* Pass [additional settings](https://boost.yandex.ru/doc/en/ad-monetization/dev/android/target-adfox.md) if you're using Adfox.
* Register an `InterstitialAdEventListener` to listen for ad event callbacks.
* Display the `InterstitialAd` object.

## Features of interstitial ad integration {#features}

1. All calls to Yandex Mobile Ads SDK methods must be made from the main thread.

2. If the `onAdFailedToLoad()` callback returns an error, don't try to load a new ad again. If there's no other option, limit the number of ad load retries. This will help avoid constant unsuccessful requests and connection issues if there are limitations.

3. We recommend maintaining a strong reference to the loader and ad throughout the lifecycle of the screen that hosts interactions with the ad to avoid cleanup by the garbage cleaner.

4. We recommend using a single instance of `InterstitialAdLoader` for all ad loads to improve performance.

## Loading ads {#load}

To upload interstitial ads, create and set up the `InterstitialAdLoader` object.

For that, you'll need Activity or Application context.

To notify when ads load or fail to load, set the `InterstitialAdLoadListener` callback method listener for the `InterstitialAdLoader` object.

To load an ad, you need the ad placement ID obtained in the Boost interface (adUnitId).

You can extend ad request parameters with the `AdRequest.Builder()` class to include information about the user's interests, page context, location, and other additional data in the ad request. Adding extra context to ad requests can greatly improve ad relevance. To learn more, see [Ad targeting](https://boost.yandex.ru/doc/en/ad-monetization/dev/android/target.md).

Once the ad is loaded (by calling the `onAdLoaded(interstitialAd: InterstitialAd)` method), save the link to the loaded `InterstitialAd` before its display is completed.

The following example shows how to load an interstitial ad from Activity:

{% list tabs %}

   - Kotlin

     ```kotlin
     class InterstitialAdActivity : AppCompatActivity(R.layout.activity_interstitial_ad) {
         private var interstitialAd: InterstitialAd? = null
         private var interstitialAdLoader: InterstitialAdLoader? = null
         private lateinit var binding: ActivityInterstitialAdBinding

         override fun onCreate(savedInstanceState: Bundle?) {
             super.onCreate(savedInstanceState)
             binding = ActivityInterstitialAdBinding.inflate(layoutInflater)
             setContentView(binding.root)

             // Interstitial ads loading should occur after initialization of the SDK.
             // Initialize SDK as early as possible, for example in Application.onCreate or Activity.onCreate
             interstitialAdLoader = InterstitialAdLoader(this)
             loadInterstitialAd()
         }

         private fun loadInterstitialAd() {
             val adRequest = AdRequest.Builder("your-ad-unit-id").build()
             interstitialAdLoader?.loadAd(adRequest, object : InterstitialAdLoadListener {
                 override fun onAdLoaded(ad: InterstitialAd) {
                     interstitialAd = ad
                     // The ad was loaded successfully. Now you can show loaded ad.
                 }

                 override fun onAdFailedToLoad(adRequestError: AdRequestError) {
                     // Ad failed to load with AdRequestError.
                     // Attempting to load a new ad from the onAdFailedToLoad() method is strongly discouraged.
                 }
             })
         }
     }
     ```

   - Java

     ```java
     public class InterstitialAdActivity extends AppCompatActivity {
         @Nullable
         private InterstitialAd mInterstitialAd = null;
         @Nullable
         private InterstitialAdLoader mInterstitialAdLoader = null;
         private ActivityInterstitialAdBinding mBinding;

         public InterstitialAdActivity() {
             super(R.layout.activity_interstitial_ad);
         }

         @Override
         protected void onCreate(@Nullable Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             mBinding = ActivityInterstitialAdBinding.inflate(getLayoutInflater());
             setContentView(mBinding.getRoot());

             // Interstitial ads loading should occur after initialization of the SDK.
             // Initialize SDK as early as possible, for example in Application.onCreate or Activity.onCreate
             mInterstitialAdLoader = new InterstitialAdLoader(this);
             loadInterstitialAd();
         }

         private void loadInterstitialAd() {
             if (mInterstitialAdLoader != null) {
                 final AdRequest adRequest =
                     new AdRequest.Builder("your-ad-unit-id").build();
                 mInterstitialAdLoader.loadAd(adRequest, new InterstitialAdLoadListener() {
                     @Override
                     public void onAdLoaded(@NonNull final InterstitialAd interstitialAd) {
                         mInterstitialAd = interstitialAd;
                         // The ad was loaded successfully. Now you can show loaded ad.
                     }

                     @Override
                     public void onAdFailedToLoad(@NonNull final AdRequestError adRequestError){
                         // Ad failed to load with AdRequestError.
                         // Attempting to load a new ad from the onAdFailedToLoad() method is strongly discouraged.
                     }
                 });
             }
         }
     }
     ```
{% endlist %}

<!-- source: en/ad-monetization/dev/_includes/ad-attributes.md -->
If you serve ads through Adfox, then after the banner ad response, the `campaignId`, `bannerId`, and `placeId` data can be accessed from the `interstitialAdLoader` objects using the `adAttributes` property of the `AdAttributes` type.
<!-- endsource: en/ad-monetization/dev/_includes/ad-attributes.md -->

## Displaying ads {#ad-view}

Interstitial ads should be displayed during natural pauses in the app's usage. A good example of this would be impressions between game levels or when a user completes an action, such as downloading a file.

Before displaying ads, set an `InterstitialAdEventListener` to listen for ad event callbacks.

To render an ad, you'll need to pass the Activity to the show method of the loaded ad:

{% list tabs %}

   - Kotlin

     ```kotlin
     private fun showAd() {
         interstitialAd?.apply {
             setAdEventListener(object : InterstitialAdEventListener {
                 override fun onAdShown() {
                     // Called when ad is shown.
                 }
                 override fun onAdFailedToShow(adError: AdError) {
            	     // Called when an InterstitialAd failed to show.
                     // Clean resources after Ad dismissed
                     interstitialAd?.setAdEventListener(null)
                     interstitialAd = null

                     // Now you can preload the next interstitial ad.
                     loadInterstitialAd()
                 }
                 override fun onAdDismissed() {
                     // Called when ad is dismissed.
                     // Clean resources after Ad dismissed
                     interstitialAd?.setAdEventListener(null)
                     interstitialAd = null

                     // Now you can preload the next interstitial ad.
                     loadInterstitialAd()
                }
                 override fun onAdClicked() {
                     // Called when a click is recorded for an ad.
                 }
                 override fun onAdImpression(impressionData: ImpressionData?) {
                     // Called when an impression is recorded for an ad.
                 }
             })
             show(this@Activity)
         }
     }
     ```

   - Java

     ```java
     private void showAd() {
         if (mInterstitialAd != null) {
             mInterstitialAd.setAdEventListener(new InterstitialAdEventListener() {
                 @Override
                 public void onAdShown() {
                     // Called when ad is shown.
                 }

                 @Override
                 public void onAdFailedToShow(@NonNull final AdError adError) {
                     // Called when an InterstitialAd failed to show.
                 }

                 @Override
                 public void onAdDismissed() {
                     // Called when ad is dismissed.
                     // Clean resources after Ad dismissed
                     if (mInterstitialAd != null) {
                         mInterstitialAd.setAdEventListener(null);
                         mInterstitialAd = null;
                     }

                     // Now you can preload the next interstitial ad.
                     loadInterstitialAd();
                 }

                 @Override
                 public void onAdClicked() {
                     // Called when a click is recorded for an ad.
                 }

                 @Override
                 public void onAdImpression(@Nullable final ImpressionData impressionData) {
                     // Called when an impression is recorded for an ad.
                 }
             });
             mInterstitialAd.show(this);
         }
     }
     ```
{% endlist %}

## Releasing resources {#destroy}

Don't store links to previously rendered ads. Call `setAdEventListener(null)` for previously rendered ads.
That releases the resources and prevents memory leaks.

{% list tabs %}

   - Kotlin

     ```kotlin
     override fun onDestroy() {
         super.onDestroy()
         interstitialAdLoader = null
         destroyInterstitialAd()
     }

     private fun destroyInterstitialAd() {
         interstitialAd?.setAdEventListener(null)
         interstitialAd = null
     }
     ```

   - Java

     ```java
     @Override
     protected void onDestroy(){
         super.onDestroy();
         mInterstitialAdLoader = null;
         destroyInterstitialAd();
     }

     private void destroyInterstitialAd() {
         if (mInterstitialAd != null) {
             mInterstitialAd.setAdEventListener(null);
             mInterstitialAd = null;
         }
     }
     ```
{% endlist %}

## Testing interstitial ad integration {#test}

<!-- source: en/ad-monetization/dev/_includes/test-android-interstitial.md -->
### Using demo ad units for ad testing {#demo-blocks}

Use test ads to check your interstitial ad integration and the app itself. To make sure that test ads are returned for each ad request, you can use a special demo ad placement ID.

Demo adUnitId: `demo-interstitial-yandex`.

{% note warning %}

Before publishing your app in the store, make sure to replace the demo placement ID with the real ID you obtained in the Boost interface.

{% endnote %}

For the list of all available demo ad placement IDs, see [Demo ad units for testing](https://boost.yandex.ru/doc/en/ad-monetization/dev/android/demo-blocks.md).

### Testing ad integration {#test-int}

You can check if your interstitial ads are integrated correctly using the SDK's built-in analyzer. A detailed report with the test results will appear in the log.

To view the report, search for the keyword “YandexAds” in [Logcat](https://developer.android.com/studio/command-line/logcat), a tool for debugging Android apps.
```bash
adb logcat -v brief '*:S YandexAds'
```

If the integration is successful, the following message is returned:
```bash
adb logcat -v brief '*:S YandexAds'
mobileads$ adb logcat -v brief '*:S YandexAds'
I/YandexAds(13719): [Integration] Ad type interstitial was integrated successfully
```

If there are any interstitial ad integration issues, you'll get a detailed issue report and troubleshooting recommendations.
<!-- endsource: en/ad-monetization/dev/_includes/test-android-interstitial.md -->

## Additional resources {#resources}

* <!-- source: en/ad-monetization/dev/_includes/github-pubdev-links.md -->
  Link to [GitHub](https://github.com/yandexmobile/yandex-ads-sdk-android).
  <!-- endsource: en/ad-monetization/dev/_includes/github-pubdev-links.md -->
