---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://ads.yandex.com/helpcenter/en/dev/android7/release/6-0-0-migration.md
  - https://ads.yandex.com/helpcenter/ru/dev/android7/release/6-0-0-migration.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ads.yandex.com/helpcenter/en/llms.txt


# Guide for migrating to version 6

{% note warning %}

Make sure to update your used [Yandex Mediation](https://ads.yandex.com/helpcenter/en/dev/android7/list-network.md) adapters and [adapters for third-party mediation networks](https://ads.yandex.com/helpcenter/en/dev/android7/third-party-mediation.md) to the latest version. Older versions may cause adapter integration errors that can prevent your ads from being served.

{% endnote %}

## Manual initialization

Manual SDK initialization process changed. You now need to deliver the callback to the `MobileAds.initialize()` method when initializing the app.

{% list tabs %}

- Kotlin

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

- Java

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

## Banners

Renamed the `AdSize` class to `BannerAdSize`. Removed the `fixedSize(int width, int height)`, `flexibleSize(int width, int maxHeight)`, and `stickySize(int width)` methods.

Use methods depending on the ad type:

Use the `BannerAdSize.stickySize(Context context, int width)` method to create an adaptive sticky banner.

> That is a small, automatically updated ad placed at the top or bottom of the app screen.
>
> It does not overlap the main app content and is often used in game apps.
>
> The height of a sticky banner is determined automatically, adapting to the screen size of the device and not taking up more than 15% of the screen height.

{% note warning %}

Version 6.0.0 added autorefresh support for adaptive sticky banners.

If you have previously implemented autorefresh for sticky banners, disable it.

{% endnote %}

To create an adaptive inline banner, use the `BannerAdSize.inlineSize(Context context, int width, int maxHeight)` method.

> Adaptive inline banners are a flexible format of banner advertising, providing maximum efficiency by optimizing the ad size on each device.
>
> The height of the banner is adjusted automatically and might reach the device screen height.
>
> Typically, that format is used in feed-based apps or contexts where it's okay to focus primarily on the ad.

For backward compatibility, we added the `fixedSize(Context context, int width, int height)` method instead of `fixedSize(int width, int height)`, but we don't recommend using it. Use `inlineSize(Context context, int width, int maxHeight)` or `stickySize(Context context, int width)` instead. In SDK 6.0.0, the height of the banner is calculated automatically and known before the ad request is sent. You can use this height in your screen layout.

## Rewarded ads

We changed the approach to creating and loading ads. We now provide the `RewardedAdLoader` loader object, which loads the ads, and the `RewardedAd` ad object retrieved by loader callback methods from the `RewardedAdLoadListener`.

To learn more about the new API, see the [SDK reference](https://doc-static.yandex.net/src/support/RSYA-RMP/mobile-ads/ru/javadoc/com/yandex/mobile/ads/rewarded/package-summary.html).

#|
||
Ad loading
| **SDK 5**

A single object for ad loading and rendering:

{% list tabs %}

- Kotlin

   ```kotlin
   val rewardedAd = RewardedAd(this@Activity).apply {
       setAdUnitId("your-ad-unit-id")
       setAdEventListener(this)
       loadAd(adRequest)
   }
   ```

- Java

   ```java
   final RewardedAd rewardedAd = new RewardedAd(this);
   rewardedAd.setAdUnitId("your-ad-unit-id");
   rewardedAd.setAdEventListener(this);
   rewardedAd.loadAd(adRequest);
   ```
{% endlist %}

**SDK 6**

`RewardedAdLoader` for loading multiple ads: You don't need to pass the Activity context for loading ads.

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

{% list tabs %}

- Kotlin

   ```kotlin
   val loader = RewardedAdLoader(context).apply {
       setAdLoadListener(object : RewardedAdLoadListener {
           override fun onAdLoaded(rewardedAd: RewardedAd) {
               // Save rewardedAd to a local variable
               // Now rewardedAd is ready to be shown
           }

           override fun onAdFailedToLoad(adRequestError: AdRequestError) {}
       })
   }
   loader.loadAd(AdRequestConfiguration.Builder("your-ad-unit-id").build())
   ```

- Java

   ```java
   final RewardedAdLoader loader = new RewardedAdLoader(this);
   loader.setAdLoadListener(new RewardedAdLoadListener() {
       @Override
       public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
           // Save rewardedAd to a local variable
           // Now rewardedAd is ready to be shown
       }

       @Override
       public void onAdFailedToLoad(@NonNull AdRequestError adRequestError) {}
   });
   loader.loadAd(new AdRequestConfiguration.Builder("your-ad-unit-id").build());
   ```
{% endlist %}

||
||
Ad rendering
| **SDK 5**

Before showing the ad, see if it loaded.

{% list tabs %}

- Kotlin

   ```kotlin
   if (rewardedAd.isLoaded()) {
       rewardedAd.show()
   }
   ```

- Java

   ```java
   if (rewardedAd.isLoaded()) {
       rewardedAd.show();
   }
   ```
{% endlist %}

**SDK 6**

You don't need to check to see if the ad is loaded.

The ad is ready for rendering after a `RewardedAd` instance is returned by the `onAdLoaded` callback method for the ad loader.

To render the ad, you need to pass Activity:

{% list tabs %}

- Kotlin

   ```kotlin
   rewardedAd.show(activity)
   ```

- Java

   ```java
   rewardedAd.show(activity);
   ```
{% endlist %}

||
||
`RewardedAd` ad object
| **SDK 5**

A class that combines ad loading and rendering.

**SDK 6**

Interface of a loaded ad. Added the `getInfo()` method for obtaining information about the ad.

{% list tabs %}

- Kotlin

   ```kotlin
   interface RewardedAd {
       fun setAdEventListener(rewardedAdEventListener: RewardedAdEventListener)

       fun show(activity: Activity)

       fun getInfo(): AdInfo
   }
   ```

- Java

   ```java
   interface RewardedAd {
       void setAdEventListener(@Nullable RewardedAdEventListener rewardedAdEventListener);

       void show(@NonNull Activity activity);

       @NonNull
       AdInfo getInfo();
   }
   ```
{% endlist %}

||
||
Callback methods
| **SDK 5**

A single callback method interface that combines event loading and rendering:

{% list tabs %}

- Kotlin

   ```kotlin
   interface RewardedAdEventListener {

       fun onLoaded()

       fun onRewarded(reward: Reward)

       fun onAdFailedToLoad(adRequestError: AdRequestError)

       fun onAdShown()

       fun onAdDismissed()

       fun onLeftApplication()

       fun onReturnedToApplication()
   }
   ```

- Java

   ```java
   interface RewardedAdEventListener {

       public void onLoaded();

       public void onRewarded(@NonNull Reward reward);

       public void onAdFailedToLoad(@NonNull AdRequestError adRequestError);

       public void onAdShown();

       public void onAdDismissed();

       public void onLeftApplication();

       public void onReturnedToApplication();
   }
   ```
{% endlist %}

**SDK 6**

The `RewardedAdEventListener` interface is divided into two parts: callback methods for loading `RewardedAdLoadListener` and rendering `RewardedAdEventListener`.

Removed the `onLeftApplication()` and `onReturnedToApplication()` methods.

Added the `onAdFailedToShow(AdError)` method.

{% list tabs %}

- Kotlin

   ```kotlin
   interface RewardedAdLoadListener {
       fun onAdLoaded(rewardedAd: RewardedAd)

       fun onAdFailedToLoad(adRequestError: AdRequestError)
   }

   interface RewardedAdEventListener {
       fun onAdShown()

       fun onAdFailedToShow(adError: AdError)

       fun onAdDismissed()

       fun onAdClicked()

       fun onAdImpression(impressionData: ImpressionData)

       fun onRewarded(reward: Reward)
   }
   ```

- Java

   ```java
   interface RewardedAdLoadListener {
       void onAdLoaded(@NonNull RewardedAd rewardedAd);

       void onAdFailedToLoad(@NonNull AdRequestError adRequestError);
   }

   interface RewardedAdEventListener {
       void onAdShown();

       void onAdFailedToShow(@NonNull AdError adError);

       void onAdDismissed();

       void onAdClicked();

       void onAdImpression(@Nullable ImpressionData impressionData);

       void onRewarded(@NonNull Reward reward);
   }
   ```
{% endlist %}

||
||
Cleaning the `RewardedAd` ad object
| **SDK 5**

Call the `onDestroy()` method and stop keeping the ad object reference.

**SDK 6**

The `onDestroy()` method has been removed.

To clean an ad object, pass `null` to the function for setting a listener for `rewardedAd.setAdEventListener` callback methods and stop keeping the ad object reference:

{% list tabs %}

- Kotlin

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

- Java

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

||
|#

## Interstitial advertising

We changed the approach to creating and loading ads. We now provide the `InterstitialAdLoader` loader object, which loads the ads, and the `InterstitialAd` ad object retrieved by the loader callback methods from the `InterstitialAdLoadListener`.

For more details about the new API, see the [SDK reference](https://doc-static.yandex.net/src/support/RSYA-RMP/mobile-ads/ru/javadoc/com/yandex/mobile/ads/interstitial/package-summary.html).

#|
||
Ad loading
| **SDK 5**

A single object for ad loading and rendering:

{% list tabs %}

- Kotlin

   ```kotlin
   val interstitialAd = InterstitialAd(this@Activity).apply {
   setAdUnitId("your-ad-unit-id")
   setAdEventListener(this)
   loadAd(adRequest)
   }
   ```

- Java

   ```java
   final InterstitialAd interstitialAd = new InterstitialAd(this);
   interstitialAd.setAdUnitId("your-ad-unit-id");
   interstitialAd.setAdEventListener(this);
   interstitialAd.loadAd(adRequest);
   ```
{% endlist %}

**SDK 6**

`InterstitialAdLoader` for loading multiple ads. You don't need to pass the Activity context for loading ads.

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

{% list tabs %}

- Kotlin

   ```kotlin
   val loader = InterstitialAdLoader(context).apply {
       setAdLoadListener(object : InterstitialAdLoadListener {
           override fun onAdLoaded(interstitialAd: InterstitialAd) {
               // Save interstitialAd to a local variable
               // Now interstitialAd is ready to be shown
           }

           override fun onAdFailedToLoad(adRequestError: AdRequestError) {}
       })
   }
   loader.loadAd(AdRequestConfiguration.Builder("your-ad-unit-id").build())
   ```

- Java

   ```java
   final InterstitialAdLoader loader = new InterstitialAdLoader(this);
   loader.setAdLoadListener(new InterstitialAdLoadListener() {
       @Override
       public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
           // Save interstitialAd to a local variable
           // Now interstitialAd is ready to show
       }

       @Override
       public void onAdFailedToLoad(@NonNull AdRequestError adRequestError) {}
   });
   loader.loadAd(new AdRequestConfiguration.Builder("your-ad-unit-id").build());
   ```
{% endlist %}

||
||
Ad rendering
| **SDK 5**

{% list tabs %}

- Kotlin

   ```kotlin
   if (interstitialAd.isLoaded()) {
       interstitialAd.show()
   }
   ```

- Java

   ```java
   if (interstitialAd.isLoaded()) {
       interstitialAd.show();
   }
   ```
{% endlist %}

**SDK 6**

You don't need to check to see if the ad is loaded.

The ad is ready for rendering after an `InterstitialAd` instance is returned by the `onAdLoaded` callback method for the ad loader.

To render the ad, you need to pass Activity:

{% list tabs %}

- Kotlin

   ```kotlin
   interstitialAd.show(activity)
   ```

- Java

   ```java
   interstitialAd.show(activity);
   ```
{% endlist %}

||
||
`InterstitialAd` ad object
| **SDK 5**

A class that combines loading and rendering of an ad.

**SDK 6**

Interface of a loaded ad. Added the `getInfo()` method for getting information about the ad.

{% list tabs %}

- Kotlin

   ```kotlin
   interface InterstitialAd {
       fun setAdEventListener(interstitialAdEventListener: InterstitialAdEventListener)

       fun show(activity: Activity)

       fun getInfo(): AdInfo
   }
   ```

- Java

   ```java
   interface InterstitialAd {
       void setAdEventListener(@Nullable InterstitialAdEventListener interstitialAdEventListener);

       void show(@NonNull Activity activity);

       @NonNull
       AdInfo getInfo();
   }
   ```
{% endlist %}

||
||
Callback methods
| **SDK 5**

A single callback method interface that combines event loading and rendering:

{% list tabs %}

- Kotlin

   ```kotlin
   interface InterstitialAdEventListener {

       fun onLoaded()

       fun onAdFailedToLoad(adRequestError: AdRequestError)

       fun onAdShown()

       fun onAdDismissed()

       fun onLeftApplication()

       fun onReturnedToApplication()
   }
   ```

- Java

   ```java
   interface InterstitialAdEventListener {

       public void onLoaded();

       public void onAdFailedToLoad(@NonNull AdRequestError adRequestError);

       public void onAdShown();

       public void onAdDismissed();

       public void onLeftApplication();

       public void onReturnedToApplication();
   }
   ```
{% endlist %}

**SDK 6**

The `InterstitialAdEventListener` interface is divided into two parts: the load callback methods from `InterstitialAdLoadListener` and rendering methods from `InterstitialAdEventListener`.

Removed the `onLeftApplication()` and `onReturnedToApplication()` methods.

Added the `onAdFailedToShow(AdError)` method.

{% list tabs %}

- Kotlin

   ```kotlin
   interface InterstitialAdLoadListener {
       fun onAdLoaded(interstitialAd: InterstitialAd)

       fun onAdFailedToLoad(adRequestError: AdRequestError)
   }

   interface InterstitialAdEventListener {
       fun onAdShown()

       fun onAdFailedToShow(adError: AdError)

       fun onAdDismissed()

       fun onAdClicked()

       fun onAdImpression(impressionData: ImpressionData)
   }
   ```

- Java

   ```java
   interface InterstitialAdLoadListener {
       void onAdLoaded(@NonNull InterstitialAd interstitialAd);

       void onAdFailedToLoad(@NonNull AdRequestError adRequestError);
   }

   interface InterstitialAdEventListener {
       void onAdShown();

       void onAdFailedToShow(@NonNull AdError adError);

       void onAdDismissed();

       void onAdClicked();

       void onAdImpression(@Nullable ImpressionData impressionData);
   }
   ```
{% endlist %}

||
||
Cleaning the `InterstitialAd` ad object
| **SDK 5**

Call the `onDestroy()` method and stop keeping the ad object reference.

**SDK 6**

The `onDestroy()` method has been removed.

To clean an ad object, pass `null` to the function for setting a listener for `interstitialAd.setAdEventListener` callback methods and stop keeping the ad object reference:

{% list tabs %}

- Kotlin

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

- Java

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

||
|#

## App open ad

Added a new ad format: app open ad. To learn more, see [App open ads](https://ads.yandex.com/helpcenter/en/dev/android7/app-open-ad.md).

## Yandex Mediation

{% note warning %}

Make sure to update your used [Yandex Mediation](https://ads.yandex.com/helpcenter/en/dev/android7/list-network.md) adapters and [adapters for third-party mediation networks](https://ads.yandex.com/helpcenter/en/dev/android7/third-party-mediation.md) to the latest version. Older versions may cause adapter integration errors that can prevent your ads from being served.

{% endnote %}

### New adapter versions

**Current versions of Yandex Mediation adapters (as of SDK 6.0.1 release):**

```
"com.yandex.ads.mediation:mobileads-adcolony": "4.8.0.6",
"com.yandex.ads.mediation:mobileads-applovin": "11.11.2.0",
"com.yandex.ads.mediation:mobileads-chartboost": "9.3.1.0",
"com.yandex.ads.mediation:mobileads-google": "22.2.0.0",
"com.yandex.ads.mediation:mobileads-inmobi": "10.5.5.0",
"com.yandex.ads.mediation:mobileads-ironsource": "7.4.0.0",
"com.yandex.ads.mediation:mobileads-mintegral": "16.4.71.1",
"com.yandex.ads.mediation:mobileads-mytarget": "5.18.0.0",
"com.yandex.ads.mediation:mobileads-pangle": "5.3.0.4.1",
"com.yandex.ads.mediation:mobileads-startapp": "4.11.0.2",
"com.yandex.ads.mediation:mobileads-tapjoy": "13.1.2.0",
"com.yandex.ads.mediation:mobileads-unityads": "4.8.0.0",
"com.yandex.ads.mediation:mobileads-vungle": "6.12.1.3",
```

**Current versions of adapters for third-party mediation platforms (as of SDK 6.0.1 release):**

```
"com.yandex.ads.adapter:admob-mobileads": "6.0.1.0",
"com.yandex.ads.adapter:ironsource-mobileads": "6.0.1.0"
```

### Renaming the Google AdMob (ex. AdMob) adapter

Renamed the `com.yandex.ads.mediation:mobileads-admob` artifact as `com.yandex.ads.mediation:mobileads-google`.

If you use the standardized Yandex Mediation build, you don't have to do anything. If you add adapters manually, replace the gradle dependency in your project.

#|
|| **SDK 5**
```gradle
implementation 'com.yandex.ads.mediation:mobileads-admob:<version>'
```
| **SDK 6**
```gradle
implementation 'com.yandex.ads.mediation:mobileads-google:<version>'
```
||
|#

Here you can find the complete examples for integrations:

* <!-- 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 -->
