---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ads.yandex.com/helpcenter/en/dev/android7/rewarded.md
  - https://ads.yandex.com/helpcenter/ru/dev/android7/rewarded.md
  - href: en/dev/android7/rewarded.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

# Rewarded ads

<!-- source: en/dev/_includes7/rewarded.md -->
Rewarded ads are a popular full-screen ad format, where the user receives a reward for viewing the ad.
<!-- endsource: en/dev/_includes7/rewarded.md -->

<!-- source: en/dev/_includes7/rewarded.md -->
The display of this ad type is activated by the user, for instance, to receive a bonus or additional life in a game.
<!-- endsource: en/dev/_includes7/rewarded.md -->

<!-- source: en/dev/_includes7/rewarded.md -->
High user motivation makes this ad format the most popular and profitable in free apps.
<!-- endsource: en/dev/_includes7/rewarded.md -->

{% cut "Appearance" %}

{% list tabs %}

- Text and image ads

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

- Video ads

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

{% endlist %}

{% endcut %}

This guide will show how to integrate rewarded ads into Android apps. In addition to code examples and instructions, it contains format-specific recommendations and links to additional resources.

## Prerequisite {#pre}

<!-- source: en/dev/_includes7/pre-android.md -->
1. Follow the SDK integration steps described in [Quick start](https://ads.yandex.com/helpcenter/en/dev/android7/quick-start.md).
2. [Initialize](https://ads.yandex.com/helpcenter/en/dev/android7/quick-start.md#init) your ad SDK in advance.
3. Make sure you're running the latest [Yandex Mobile Ads SDK](https://ads.yandex.com/helpcenter/en/dev/android7/changelog-android.md) version. If you're using mediation, make sure you're also running the latest version of the [unified build](https://ads.yandex.com/helpcenter/en/dev/android7/changelog-android.md).
<!-- endsource: en/dev/_includes7/pre-android.md -->

## Implementation {#implement}

Key steps for integrating rewarded ads:

* Create and configure the `RewardedAdLoader` ad loader.
* Register the listener for ad load callback methods: `RewardedAdLoadListener`.
* Load the ad.
* Register the `RewardedAdEventListener` listener for ad event callback methods.
* Render the `RewardedAd`.
* Reward the user for viewing the ad.

## Features of rewarded ad integration {#features}

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

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

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

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

## Loading ads {#load}

To load rewarded ads, create and set up the `RewardedAdLoader` object.

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

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

To load an ad, you'll need the ad unit ID from the Yandex Advertising Network interface (adUnitId).

You can expand the ad request parameters through `AdRequestConfiguration.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/android7/target.md) section.

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

The following example shows how to load a rewarded ad from Activity:

{% list tabs %}

- Kotlin

   ```kotlin
   class RewardedAdActivity : AppCompatActivity(R.layout.activity_rewarded_ad) {
       private var rewardedAd: RewardedAd? = null
       private var rewardedAdLoader: RewardedAdLoader? = null
       private lateinit var binding: ActivityRewardedAdBinding

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

           // Rewarded ads loading should occur after initialization of the SDK.
           // Initialize SDK as early as possible, for example in Application.onCreate or Activity.onCreate
           rewardedAdLoader = RewardedAdLoader(this).apply {
               setAdLoadListener(object : RewardedAdLoadListener {
                   override fun onAdLoaded(rewardedAd: RewardedAd) {
                       this.rewardedAd = rewardedAd
                       // The ad was loaded successfully. You can now show the 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.
                   }
               })
           }
           loadRewardedAd()
       }

       private fun loadRewardedAd() {
           val adRequestConfiguration = AdRequestConfiguration.Builder("your-ad-unit-id").build()
           rewardedAdLoader?.loadAd(adRequestConfiguration)
       }
   }
   ```

- Java

   ```java
   public class RewardedAdActivity extends AppCompatActivity {
       @Nullable
       private RewardedAd mRewardedAd = null;
       @Nullable
       private RewardedAdLoader mRewardedAdLoader = null;
       private ActivityRewardedAdBinding mBinding;

       public RewardedAdActivity() {
           super(R.layout.activity_rewarded_ad);
       }

       @Override
       protected void onCreate(@Nullable Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           mBinding = ActivityRewardedAdBinding.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
           mRewardedAdLoader = new RewardedAdLoader(this);
           mRewardedAdLoader.setAdLoadListener(new RewardedAdLoadListener() {
               @Override
               public void onAdLoaded(@NonNull final RewardedAd rewardedAd) {
                   mRewardedAd = rewardedAd;
                   // The ad was loaded successfully. You can now show the 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.
               }
           });
           loadRewardedAd();
       }

       private void loadRewardedAd() {
           if (mRewardedAdLoader != null ) {
               final AdRequestConfiguration adRequestConfiguration =
                   new AdRequestConfiguration.Builder("your-ad-unit-id").build();
               mRewardedAdLoader.loadAd(adRequestConfiguration);
           }
       }
   }
   ```
{% endlist %}

## Ad rendering {#ad-view}

<!-- source: en/dev/_includes7/rewarded.md -->
Rewarded advertising is an incentive-based ad format that allows the user to receive a reward for viewing the ad. The reward could be an extra life or advancing to the next level in a game. The reward format is determined at the app level.
<!-- endsource: en/dev/_includes7/rewarded.md -->

To track the rewarded ad lifecycle and issue rewards, set the `RewardedAdEventListener` callback method listener for the RewardedAd object.

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() {
       rewardedAd?.apply {
           setAdEventListener(object : RewardedAdEventListener {
               override fun onAdShown() {
                   // Called when an ad is shown.
               }

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

               override fun onAdDismissed() {
                   // Called when an ad is dismissed.
                   // Clean resources after Ad dismissed
                   rewardedAd?.setAdEventListener(null)
                   rewardedAd = null

                   // Now you can preload the next rewarded ad.
                   loadRewardedAd()
               }

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

               override fun onRewarded(reward: Reward) {
                   // Called when the user can be rewarded.
               }
           })
           show(this@Activity)
       }
   }
   ```

- Java

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

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

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

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

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

               @Override
               public void onRewarded(@NonNull final Reward reward) {
                   // Called when the user can be rewarded.
               }
           });
           mRewardedAd.show(this);
       }
   }
   ```
{% endlist %}

## Releasing resources {#destroy}

Don't store links to previously rendered ads. Call `setAdEventListener(null)` for previously rendered ads.
Call `setAdLoadListener(null)` for the loader if it's no longer used.
That releases the resources and prevents memory leaks.

{% list tabs %}

- Kotlin

   ```kotlin
   override fun onDestroy() {
       super.onDestroy()
       rewardedAdLoader.setAdLoadListener(null)
       rewardedAdLoader = null
       destroyRewardedAd()
   }

   private fun destroyRewardedAd() {
       rewardedAd?.setAdEventListener(null)
       rewardedAd = null
   }
   ```

- Java

   ```java
   @Override
   protected void onDestroy() {
       super.onDestroy();
       if (mRewardedAdLoader != null) {
           mRewardedAdLoader.setAdLoadListener(null);
           mRewardedAdLoader = null;
       }
       destroyRewardedAd();
   }

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

## Testing the rewarded ad integration {#test}

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

We recommend using test ads to test your rewarded ad integration and your app itself.

To guarantee that test ads are returned for every ad request, we created a special demo ad placement ID. Use it to check your ad integration.

Demo adUnitId: `demo-rewarded-yandex`.

{% note warning %}

Before publishing your app in the store, make sure to replace the demo ad placement ID with a real one obtained from the Yandex Advertising Network interface.

{% endnote %}

You can find the list of available demo ad placement IDs in the [Demo ad units for testing](https://ads.yandex.com/helpcenter/en/dev/android7/demo-blocks.md) section.

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

You can test your rewarded ad integration using the SDK's built-in analyzer.

The tool checks makes sure your rewarded ads are integrated properly and outputs a detailed report to the log.
To view the report, search for the “YandexAds” keyword in the [Logcat](https://developer.android.com/studio/command-line/logcat) tool for Android app debugging.
```bash
adb logcat -v brief '*:S YandexAds'
```

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

If you're having problems integrating rewarded ads, you'll get a detailed report on the issues and recommendations for how to fix them.
<!-- endsource: en/dev/_includes7/test-android-rewarded.md -->

## Additional resources {#resources}

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