---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://boost.yandex.ru/doc/en/ad-monetization/dev/android/feed-ad.md
  - https://boost.yandex.ru/doc/ru/ad-monetization/dev/android/feed-ad.md
  - href: en/ad-monetization/dev/android/feed-ad.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

# Ad feed

<!-- source: en/ad-monetization/dev/_includes/feed-ad.md -->
Ad feeds are units that consist of a sequence of ads. Feeds can be added to your app as its main content, or they may come after the existing content. Feeds may contain dozens of ads loaded in parts, multiple ads at a time.
<!-- endsource: en/ad-monetization/dev/_includes/feed-ad.md -->

This guide covers the process of integrating ad feeds into Android apps. Besides code samples and instructions, it contains format-specific recommendations and links to additional resources.

{% cut "Appearance" %}

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

{% endcut %}

## Prerequisite {#pre}

<!-- source: en/ad-monetization/dev/_includes/pre-android-feed.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're using the [latest version of the Yandex Mobile Ads SDK](https://boost.yandex.ru/doc/en/ad-monetization/dev/android/changelog-android.md).
<!-- endsource: en/ad-monetization/dev/_includes/pre-android-feed.md -->

## Implementation {#implement}

Key steps for integrating ad feeds:

* Configure your ad feed's appearance using the `FeedAdAppearance` object.
* Create and set up a request configuration using the `AdRequest` object.
* Create an ad feed object named `FeedAd` and register a `FeedAdLoadListener` for ad load callback methods.
* Preload your ads as soon as possible by calling `feedAd.preloadAd()`.
* Create an adapter named `FeedAdAdapter` and register a `FeedAdEventListener` for event callback methods.
* Set the `FeedAdAdapter` in the `RecyclerView.adapter`.

### Key steps

1. Create an ad feed's appearance configuration object named `FeedAdAppearance`.

   The following parameters are available:

   * `cardWidth`(required): Sets the width of a served ad in dp (density-independent pixels). Calculate the parameter value based on the screen width minus the required side padding.
   * `cardCornerRadius`: Sets the radius of rounded corners for a served ad in dp (density-independent pixels).
  
   {% list tabs %}

   - Kotlin

     ```kotlin
     val feedMarginDp = 24
     val screenWidthDp = (screenWidth / resources.displayMetrics.density).roundToInt()
     val cardWidthDp = screenWidthDp - 2 * feedMarginDp
     val cardCornerRadiusDp = 16.0

     val feedAdAppearance = FeedAdAppearance.Builder(cardWidthDp)
	           .setCardCornerRadius(cardCornerRadiusDp)
	           .build()
     ```
  
   - Java

     ```java
     DisplayMetrics displayMetrics = getResources().getDisplayMetrics();

     int feedMarginDp = 24;
     int screenWidthDp = Math.round(displayMetrics.widthPixels / displayMetrics.density);
     val cardWidthDp = screenWidthDp - 2 * feedMarginDp;
     double cardCornerRadius = 16.0;

     FeedAdAppearance feedAdAppearance = new FeedAdAppearance.Builder(cardWidth)
         .setCardCornerRadius(cardCornerRadius)
         .build();
     ```

   {% endlist %}

2. Create and configure a `AdRequest` object.

   You'll need the ad placement ID obtained in the Boost interface (`AD_UNIT_ID`).

   You can expand ad request parameters by providing information about the user's interests, page context, location, and other additional data in the ad request's `Builder` methods. 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).

   {% list tabs %}

   - Kotlin

     ```kotlin
     val AD_UNIT_ID = "R-M-XXXXXX-Y" // For debugging reasons you can use "demo-feed-yandex"
     val adRequest = AdRequest.Builder(AD_UNIT_ID).build()
     ```

   - Java

     ```java
     String AD_UNIT_ID = "R-M-XXXXXX-Y"; // For debugging reasons you can use "demo-feed-yandex"
     AdRequest adRequest = new AdRequest.Builder(AD_UNIT_ID).build();
     ```

   {% endlist %}

3. Create an ad feed object named `FeedAd` and register a `FeedAdLoadListener` for ad load callback methods.

   {% list tabs %}

   - Kotlin

     ```kotlin
     val feedAdLoadListener = object : FeedAdLoadListener {

         override fun onAdLoaded() {
    	       // Called when additional ads are received for display
         }

         override fun onAdFailedToLoad(error: AdRequestError) {
    	       // Called when additional ads request fails
         }
     }

     val feedAd = FeedAd.Builder(context, adRequest, feedAdAppearance).build()
     feedAd.loadListener = feedAdLoadListener
     ```

   - Java

     ```java
     FeedAdLoadListener feedAdLoadListener = new FeedAdLoadListener() {
         @Override
         public void onAdLoaded() {
             // Called when additional ads are received for display
         }

         @Override
         public void onAdFailedToLoad(AdRequestError error) {
             // Called when additional ads request fails
         }
     };

     FeedAd feedAd = new FeedAd.Builder(context, adRequest, feedAdAppearance).build();
     feedAd.setLoadListener(feedAdLoadListener);
     ```

   {% endlist %}

4. Preload your ad as soon as possible using the `preloadAd()` method for the `FeedAd` object. Once the ad feed is preloaded, one of the `FeedAdLoadListener` methods is called.
   
   {% list tabs %}

   - Kotlin

     ```kotlin
     feedAd.preloadAd()
     ```
   
   - Java
  
     ```java
     feedAd.preloadAd();
     ```

   {% endlist %}

5. Create an adapter named `FeedAdAdapter` and register a `FeedAdEventListener` for event callback methods.

   {% list tabs %}

   - Kotlin

     ```kotlin
     val feedAdEventListener = object : FeedAdEventListener {

         override fun onAdClicked() {
    	       // Called when user clicked on the ad
         }
    
         override fun onAdImpression(impressionData: ImpressionData?) {
    	       // Called when impression was observed
         }
     }

     val feedAdAdapter = FeedAdAdapter(feedAd)
     feedAdAdapter.eventListener = feedAdEventListener
     ```

   - Java
  
     ```java
     FeedAdEventListener feedAdEventListener = new FeedAdEventListener() {
         @Override
         public void onAdClicked() {
             // Called when user clicked on the ad
         }

         @Override
         public void onAdImpression(ImpressionData impressionData) {
             // Called when impression was observed
         }
     };

     FeedAdAdapter feedAdAdapter = new FeedAdAdapter(feedAd);
     feedAdAdapter.setEventListener(feedAdEventListener);
     ```

   {% endlist %}

6. Display the ad feed.

   {% list tabs %}

   - As the main list

     Set the created `FeedAdAdapter` in the `RecyclerView.adapter`.

     * Kotlin

       ```kotlin
       binding.feedRecyclerView.layoutManager = LinearLayoutManager(context)
       binding.feedRecyclerView.adapter = feedAdAdapter
       ```
     * Java

       ```java
       binding.feedRecyclerView.setLayoutManager(new LinearLayoutManager(context));
       binding.feedRecyclerView.setAdapter(feedAdAdapter);
       ```
  
   - In addition to an existing list

     To add your ad feed to an existing `RecyclerView` list, use the [ConcatAdapter](https://developer.android.com/reference/androidx/recyclerview/widget/ConcatAdapter).

     The [ConcatAdapter](https://developer.android.com/reference/androidx/recyclerview/widget/ConcatAdapter) allows you to combine the `RecyclerView` adapter of the existing list and the ad feed adapter. The order of passing arguments to the [ConcatAdapter](https://developer.android.com/reference/androidx/recyclerview/widget/ConcatAdapter) builder sets the order of displaying the lists of respective adapters.

     * Kotlin

       ```kotlin
       val screenContentDataAdapter = ScreenContentDataAdapter() // Your own implementation of RecyclerView.Adapter
       val concatAdapter = ConcatAdapter(listOf(screenContentDataAdapter, feedAdAdapter))

       binding.feedRecyclerView.layoutManager = LinearLayoutManager(context)
       binding.feedRecyclerView.adapter = concatAdapter
       ```
     * Java

       ```java
       ScreenContentDataAdapter screenContentDataAdapter = new ScreenContentDataAdapter(); // Your own implementation of RecyclerView.Adapter
       ConcatAdapter concatAdapter = new ConcatAdapter(Arrays.asList(screenContentDataAdapter, feedAdAdapter));

       binding.feedRecyclerView.setLayoutManager(new LinearLayoutManager(context));
       binding.feedRecyclerView.setAdapter(concatAdapter);
       ```
  
   {% endlist %}

## Specifics of ad feed integration {#features}

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

## Testing ad feed integration {#test}

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

Use test ads to check your ad feed integration and the app itself.

To make sure that test ads are returned for each ad request, we created a special demo ad placement ID designed to help you test your ad integration.

Demo Ad Unit ID: `demo-feed-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 interface Boost.

{% 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 ad feed is integrated correctly using the SDK's built-in analyzer.

This tool checks whether ads are enabled properly and outputs a detailed report to a log.
To view the report, search 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 feed was integrated successfully
```

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