---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ads.yandex.com/helpcenter/en/easy/integration/android/formats/app-open-ads.md
  - https://ads.yandex.com/helpcenter/ru/easy/integration/android/formats/app-open-ads.md
  - https://ads.yandex.com/helpcenter/zh/easy/integration/android/formats/app-open-ads.md
  - href: en/easy/integration/android/formats/app-open-ads.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://ads.yandex.com/helpcenter/en/llms.txt

# App open ads

<!-- source: en/easy/_includes/notes-android-easy-guide.md -->
{% note info %}

Examples showing how all the format types work are available in the [demo project](https://ads.yandex.com/helpcenter/en/easy/integration/android/testing.md#demo).

{% endnote %}
<!-- endsource: en/easy/_includes/notes-android-easy-guide.md -->


## Example of creating an app open ad

1. Initialize the SDK when the application starts.

   {% 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 configure the `AppOpenAdLoader` ad loader.

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

   You can extend the ad request via `AdRequest.Builder()` by passing user interests, page context, location, or other data. Extra contextual data in the request can significantly improve ad quality.

   {% 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 = new 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 an `AppOpenAdLoadListener` on the loader to receive success or failure load notifications.

   {% list tabs %}

   - Kotlin

     ```kotlin
     val appOpenAdLoadListener = object : AppOpenAdLoadListener {
        override fun onAdLoaded(appOpenAd: AppOpenAd) {
            // The ad was loaded successfully. Now you can show loaded 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.
        }
     }
     ```

   - Java

     ```java
     AppOpenAdLoadListener appOpenAdLoadListener = new AppOpenAdLoadListener() {
         @Override
         public void onAdLoaded(@NonNull final AppOpenAd appOpenAd) {
             // The ad was loaded successfully. Now you can show loaded 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.
         }
     };
     ```

   {% endlist %}

4. Load the ad using `loadAd(AdRequest, AppOpenAdLoadListener)`.

   {% list tabs %}

   - Kotlin

     ```kotlin
      private fun loadAppOpenAd() {
         appOpenAdLoader.loadAd(adRequest, appOpenAdLoadListener)
      }
      ```

   - Java

     ```java
      private void loadAppOpenAd() {
          appOpenAdLoader.loadAd(adRequest, appOpenAdLoadListener);
      }
      ```

   {% endlist %}

5. Use `LifecycleEventObserver` to handle application state changes and show the ad when the app is opened.

   {% 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 showing the ad, set the ad event callback listener `AppOpenAdEventListener`.

   {% 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. Show 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 %}

8. Release resources.

   This is required to prevent 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 %}

## Checking integration

<!-- source: en/easy/_includes/notes-android-easy-guide.md -->
Build and run your project. You can check if the integration is successful by searching the `YandexAds` keyword in **Logcat**:
<!-- endsource: en/easy/_includes/notes-android-easy-guide.md -->

```
[Integration] Ad type App Open was integrated successfully
```
