---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://ads.yandex.com/helpcenter/en/dev/android/app-open-ad.md
  - https://ads.yandex.com/helpcenter/pt/dev/android/app-open-ad.md
  - https://ads.yandex.com/helpcenter/ru/dev/android/app-open-ad.md
  - https://ads.yandex.com/helpcenter/zh/dev/android/app-open-ad.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ads.yandex.com/helpcenter/en/llms.txt

# App open ads



<!-- source: en/dev/_includes/app-open-ad.md -->
App open ads are a special ad format for monetizing app load screens. These ads can be closed at any time and are designed to be served:
* When the app is launched.
* When the app is brought to the foreground.
* When returning to the app from the background.
<!-- endsource: en/dev/_includes/app-open-ad.md -->

This guide will show how to integrate ads served when opening an Android app. In addition to code examples and instructions, it contains format-specific recommendations and links to additional resources.


## Layout

App open ads include a **Go to the app** button so users know they're in your app and can close the ad. Here's an example of what an ad looks like:

<iframe width="200" height="405.5" allow="autoplay" src="https://runtime.strm.yandex.ru/player/video/vplv635j6ybajkg2dhee?autoplay=1&mute=0&loop=1&loop=1" frameborder="0" allowfullscreen></iframe>


## Prerequisite {#pre}

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

### Terms and definitions

* **Cold start** is starting an app which is not in the RAM, creating a new app session.
* **Hot start** is switching the app from background mode, when the app is paused in the RAM, to foreground mode.

## Implementation {#implement}

1. Initialize the SDK at app start.
2. Create and set up the `AppOpenAdLoader` ad loader object.
3. Set the `AppOpenAdLoadListener` callback method listener for notifications when ads load successfully or unsuccessfully.
4. Load the ad using the `loadAd(AdRequest)` method.
5. Use [LifecycleEventObserver](https://developer.android.com/reference/androidx/lifecycle/LifecycleEventObserver) to handle app status changes and display app open ads.
6. Before rendering the ad, set the `AppOpenAdEventListener` ad callback method listener.
7. Render the ad using the `show(Activity)` method.
8. Release the resources.

### Main steps

1. Initialize the SDK at app start.

   {% list tabs %}

   - Kotlin

      ```kotlin
      YandexAds.initialize(this) {
          // Now you can use ads
      }
      ```

   - Java

      ```java
      YandexAds.initialize(this, () -> {
          // Now you can use ads
      });
      ```

   {% endlist %}

2. Create and set up the `AppOpenAdLoader` ad loader object.

   You will need the ad unit ID from the Yandex Advertising Network interface (`AD_UNIT_ID`).

   You can expand the ad request parameters through `AdRequest.Builder()` by passing user interests, contextual app data, location details, or other data. Delivering additional contextual data in the request can significantly improve your ad quality. Read more in the [Ad Targeting](https://ads.yandex.com/helpcenter/en/dev/android/target.md) section.

   {% list tabs %}

   - Kotlin

      ```kotlin
      val appOpenAdLoader: AppOpenAdLoader = AppOpenAdLoader(application)
      val AD_UNIT_ID = "R-M-XXXXXX-Y" // for debugging, you can use "demo-appopenad-yandex"
      val adRequest = AdRequest.Builder(AD_UNIT_ID).build()
      ```

   - Java

      ```java
      final AppOpenAdLoader appOpenAdLoader = AppOpenAdLoader(application);
      final String AD_UNIT_ID = "R-M-XXXXXX-Y"; // for debugging, you can use "demo-appopenad-yandex"
      final AdRequest adRequest = new AdRequest.Builder(AD_UNIT_ID).build();
      ```

   {% endlist %}

3. Set the `AppOpenAdLoadListener` callback method listener for notifications when ads load successfully or unsuccessfully.

   {% list tabs %}

   - Kotlin

      ```kotlin
      val appOpenAdLoadListener = object : AppOpenAdLoadListener {
         override fun onAdLoaded(appOpenAd: AppOpenAd) {
             // The ad was loaded successfully. You can now show the ad.
             this@Activity.appOpenAd = appOpenAd
         }

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

      appOpenAdLoader.setAdLoadListener(appOpenAdLoadListener)
      ```

   - Java

      ```java
      AppOpenAdLoadListener appOpenAdLoadListener = new AppOpenAdLoadListener() {
          @Override
          public void onAdLoaded(@NonNull final AppOpenAd appOpenAd) {
              // The ad was loaded successfully. You can now show the ad.
              mAppOpenAd = appOpenAd;
          }

          @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.
          }
      };

      appOpenAdLoader.setAdLoadListener(appOpenAdLoadListener);
      ```

   {% endlist %}

4. Load the ad using the `loadAd(AdRequest)` method.

   {% list tabs %}

   - Kotlin

      ```kotlin
      appOpenAdLoader.loadAd(adRequest)
      ```

   - Java

      ```java
      appOpenAdLoader.loadAd(adRequest);
      ```

   {% endlist %}

5. Use `LifecycleEventObserver` to handle app status changes and display app open ads.

   {% list tabs %}

   - Kotlin

      ```kotlin
      val processLifecycleObserver = DefaultProcessLifecycleObserver(
          onProcessCameForeground = ::showAppOpenAd
      )
      ProcessLifecycleOwner.get().lifecycle.addObserver(processLifecycleObserver)
      ```

   - Java

      ```java
      final DefaultProcessLifecycleObserver processLifecycleObserver = new DefaultProcessLifecycleObserver() {
          @Override
          public void onProcessCameForeground() {
              showAppOpenAd();
          }
      }

      ProcessLifecycleOwner.get().getLifecycle().addObserver(processLifecycleObserver);
      ```

   {% endlist %}

6. Before rendering the ad, set the `AppOpenAdEventListener` ad callback method listener.

   {% list tabs %}

   - Kotlin

      ```kotlin
      private inner class AdEventListener : AppOpenAdEventListener {
          override fun onAdShown() {
              // Called when ad is shown.
          }

          override fun onAdFailedToShow(adError: AdError) {
              // Called when ad failed to show.
          }

          override fun onAdDismissed() {
              // Called when ad is dismissed.
              // Clean resources after dismiss and preload new ad.
              clearAppOpenAd()
              loadAppOpenAd()
          }

          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.
              // Get Impression Level Revenue Data in argument.
          }
      }

      private val appOpenAdEventListener = AdEventListener()
      appOpenAd?.setAdEventListener(appOpenAdEventListener)
      ```

   - Java

      ```java
      AppOpenAdEventListener appOpenAdEventListener = new AppOpenAdEventListener() {
         @Override
         public void onAdShown() {
             // Called when ad is shown.
         }

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

         @Override
         public void onAdDismissed() {
             // Called when ad is dismissed.
             // Clean resources after dismiss and preload new ad.
             clearAppOpenAd();
             loadAppOpenAd();
         }

         @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.
         }
      };

      if (mAppOpenAd != null) {
         mAppOpenAd.setAdEventListener(appOpenAdEventListener);
      }
      ```

   {% endlist %}

7. Render the ad using the `show` method.

   {% list tabs %}

   - Kotlin

      ```kotlin
      private fun showAppOpenAd() {
          appOpenAd?.show(activity)
      }
      ```

   - Java

      ```java
      private void showAppOpenAd() {
          if (mAppOpenAd != null) {
             mAppOpenAd.show(activity);
          }
      }
      ```

   {% endlist %}

   <!-- source: en/dev/_includes/app-open-ad.md -->
   {% note info %}

   If the ad has already been served, calling the `show(Activity)` method will return a display error in `AppOpenAdEventListener.onAdFailedToShow(AdError)`.

   {% endnote %}
   <!-- endsource: en/dev/_includes/app-open-ad.md -->

8. Release the resources.

   That prevents memory leaks.

   {% list tabs %}

   - Kotlin

      ```kotlin
      private fun clearAppOpenAd() {
          appOpenAd?.setAdEventListener(null)
          appOpenAd = null
      }
      ```

   - Java

      ```java
      private void clearAppOpenAd() {
          if (mAppOpenAd != null) {
              mAppOpenAd.setAdEventListener(null);
              mAppOpenAd = null;
          }
      }
      ```

   {% endlist %}

## Features of app open ad integration {#features}

1. All calls to Yandex Mobile Ads SDK methods must be made from the main thread.
2. Loading can take a while, so don't increase the cold start time if the ad hasn't loaded.
3. Pre-load the ad for subsequent display during hot starts.
4. We discourage you loading app open ads and other ad formats in parallel during the app launch because the app might be downloading operational data at that time. That could overload the device and the internet connection, making the ad load longer.
5. If you received an error in the `onAdFailedToLoad()` callback, do not try to load a new ad again. If you must do so, limit the number of ad reload attempts. That will help avoid constant unsuccessful requests and connection issues when limitations arise.

## Testing ad integration at launch {#test}

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

Use test ads to check your 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-appopenad-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 Yandex Advertising Network interface.

{% endnote %}

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

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

You can check if your app open 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 App Open Ad was integrated successfully
```

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

## Recommendations

1. Don't render your app open ad before the splash screen.

   By displaying the splash screen, you enhance the user's app experience, making it more seamless and enjoyable. That will keep the user from being surprised or confused, making them sure they opened the right app. On the same screen, you can warn users about the upcoming ad. Use a loading indicator or simply a text message telling the user they will resume viewing app content after the ad.

2. If there's a delay between requesting and rendering the ad, the user might briefly open your app and then unexpectedly see an ad unrelated to the contents. That can negatively impact the user experience, so it is worth avoiding. One solution is to use the splash screen before displaying the main app content and start ad rendering from this screen. If the app opens some content after the splash screen, you're better off not rendering the ad.

3. Wait until new users open the app and use it a few times before rendering an app open ad. Only render the ad to users who have met certain criteria in the app (for example, passed a certain level, opened the app a certain number of times, or are not participating in rewarded offers). Don't render the ad immediately after the app is installed.

4. Regulate ad render frequency based on app user behavior. Don't render the ad at every cold/hot app start.

5. Only render the ad if your app has been in the background for a certain period of time (for example, 30 seconds, two minutes, 15 minutes).

6. Make sure you run thorough tests since each app is unique and requires a special approach to maximize revenue without reducing retention or time spent in the app. User behavior and engagement can change over time, so we recommend periodically testing the strategies you use for your app open ads.

## Additional resources {#resources}

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