# AdLoader API Migration Guide

# Overview

This guide explains how to migrate to the AdLoader API, which is the standard API starting from Android FiveSDK v3.0.0.

The AdLoader API consolidates the APIs used for SDK initialization and ad loading. The legacy APIs for SDK initialization and ad loading are deprecated, so code changes are required.

This document describes how to apply these changes.


# SDK Initialization

Previously, SDK initialization was done by registering an instance of FiveAdConfig to FiveAd:

With the AdLoader API, SDK initialization is performed by obtaining an AdLoader instance for a given FiveAdConfig:

Initialization fails only in very rare cases (for example, when allocating the storage area used by the SDK fails). It does not fail due to reasons such as network errors. Since there is very little chance that retrying will succeed once this initialization fails, retry logic is not required.


# Ad Loading

Previously, the ad loading flow looked like this:

  1. Create an ad object.
  2. Register a FiveAdLoadListener.
  3. Call loadAdAsync.
  4. Receive a load success callback via onFiveAdLoad.

With the AdLoader API, ad loading is done with the following steps:

  1. Create an AdSlotConfig.
  2. Call a load function on AdLoader.
  3. Receive the loaded ad object in the callback passed to the load function.

The load functions for each AdLoader ad format are as follows:

Ad Format Load function (Kotlin) Load function (Java)
Custom layout loadBannerAd(config: AdSlotConfig, initialWidth: Int, callback: LoadBannerAdCallback) loadBannerAd(@NonNull AdSlotConfig config, int initialWidth, @NonNull LoadBannerAdCallback callback)
Rewarded video loadRewardAd(config: AdSlotConfig, callback: LoadRewardAdCallback) loadRewardAd(@NonNull AdSlotConfig config, @NonNull LoadRewardAdCallback callback)
Interstitial loadInterstitialAd(config: AdSlotConfig, callback: LoadInterstitialAdCallback) loadInterstitialAd(@NonNull AdSlotConfig config, @NonNull LoadInterstitialAdCallback callback)
Native loadNativeAd(config: AdSlotConfig, initialWidth: Int, callback: LoadBannerAdCallback) loadNativeAd(@NonNull AdSlotConfig config, int initialWidth, @NonNull LoadBannerAdCallback callback)

Below, we explain how to update the implementation of a custom layout ad load flow. Even if the ad format changes, only the load function differs; the migration steps are otherwise the same. You can use this example as a reference when updating other ad formats.

# Example (Custom Layout Ad)

The following code is an example of a custom layout ad loading flow using the legacy API.

We will now rewrite this code to use the AdLoader API. In this example, we assume that the AdLoader instance has already been initialized.

First, instead of creating a FiveAdCustomLayout ad object directly, create an AdSlotConfig:

Next, use an AdLoader instance to call the appropriate load function:

FiveAdLoadListener is no longer used. Instead, you pass a callback function. Therefore, instead of implementing FiveAdLoadListener, you must move the logic previously implemented in that listener into the “ad load success” and “ad load failure” parts of the callback.

Note that, unlike the previous approach, you must use the ad object returned in the callback instead of this.fiveAdCustomLayout.

For now, let’s extract the “ad load success” and “ad load failure” parts into separate methods:

Now implement the methods for handling success and failure.

This completes the migration to the AdLoader API. If you are using setEventListener to register event listeners, that part of the code can remain unchanged.

Finally, here is the completed code: