InterstitialAdPreloader

public final class InterstitialAdPreloader


The preloader for interstitial ads.

Summary

Public methods

static boolean
destroy(String preloadId)

Stops preloading for the given preloadId and destroys all associated preloaded ads.

static void

Stops preloading and destroys preloaded ads for all preload configurations.

static @Nullable PreloadConfiguration

Returns the interstitial ad PreloadConfiguration associated with this preloadId, or null if one does not exist.

static Map<StringPreloadConfiguration>

Returns a map of all interstitial ad PreloadConfigurations, keyed by their associated preload ID.

static int

Returns the number of available ads for the given preload ID.

static boolean
isAdAvailable(String preloadId)

Determines whether least one ad is available for the given preloadId.

static @Nullable InterstitialAd
pollAd(String preloadId)

Returns an ad preloaded from start or start and removes it from the cache.

static boolean
start(String preloadId, PreloadConfiguration preloadConfiguration)

Starts preloading ads for the given preloadId and PreloadConfiguration.

static boolean
start(
    String preloadId,
    PreloadConfiguration preloadConfiguration,
    PreloadCallbackV2 preloadCallback
)

Starts preloading ads for the given preloadId, PreloadConfiguration, and .

Public methods

destroy

public static boolean destroy(String preloadId)

Stops preloading for the given preloadId and destroys all associated preloaded ads.

Parameters
String preloadId

The preload ID of the configuration to destroy.

Returns
boolean

true if an active preload configuration was destroyed. Returns false if there is no active preload configuration for the given preloadId.

destroyAll

public static void destroyAll()

Stops preloading and destroys preloaded ads for all preload configurations.

getConfiguration

public static @Nullable PreloadConfiguration getConfiguration(String preloadId)

Returns the interstitial ad PreloadConfiguration associated with this preloadId, or null if one does not exist.

Parameters
String preloadId

The preload ID linked to this configuration..

Returns
@Nullable PreloadConfiguration

The PreloadConfiguration for the given preload ID, or null if there is no configuration for the given preload ID.

getConfigurations

public static Map<StringPreloadConfigurationgetConfigurations()

Returns a map of all interstitial ad PreloadConfigurations, keyed by their associated preload ID.

Returns
Map<StringPreloadConfiguration>

The interstitial ad configurations, or an empty map if no preloaders exist.

getNumAdsAvailable

public static int getNumAdsAvailable(String preloadId)

Returns the number of available ads for the given preload ID.

Parameters
String preloadId

The preload ID to check for availability.

Returns
int

The number of available ads for the given preload ID.

isAdAvailable

public static boolean isAdAvailable(String preloadId)

Determines whether least one ad is available for the given preloadId.

Parameters
String preloadId

The preload ID to check for availability.

Returns
boolean

true if there is an available ad for the given preload ID, false otherwise.

pollAd

public static @Nullable InterstitialAd pollAd(String preloadId)

Returns an ad preloaded from start or start and removes it from the cache.

Note that this may be any of the ads preloaded for preloadId. The order returned is not guaranteed to match the order of onAdPreloaded events.

Parameters
String preloadId

The ad's preload ID.

Returns
@Nullable InterstitialAd

An interstitial ad for the given preload ID, or null if no ad is available.

start

public static boolean start(String preloadId, PreloadConfiguration preloadConfiguration)

Starts preloading ads for the given preloadId and PreloadConfiguration.

The SDK continues preloading ads until the number of ads specified by getBufferSize is reached, attempting to keep the buffer full throughout the session.

If a PreloadConfiguration was already started with preloadId, this method becomes a no-op and returns false.

Parameters
String preloadId

A string identifier for this PreloadConfiguration. Use this identifier when calling pollAd to get an ad for this configuration.

PreloadConfiguration preloadConfiguration

The configuration for preloading ads.

Returns
boolean

true if preloading started, false if the preloadId is in-use.

start

public static boolean start(
    String preloadId,
    PreloadConfiguration preloadConfiguration,
    PreloadCallbackV2 preloadCallback
)

Starts preloading ads for the given preloadId, PreloadConfiguration, and .

The SDK continues preloading ads until the number of ads specified by getBufferSize is reached, attempting to keep the buffer full throughout the session.

For each ad request, the SDK triggers either an onAdPreloaded callback upon successful preloading or an onAdFailedToPreload callback if preloading fails. The SDK automatically retries failed requests.

If a PreloadConfiguration has already started with the given preloadId, this method does nothing and returns false. becomes a no-op and returns false.

Parameters
String preloadId

A string that uniquely identifies this PreloadConfiguration. Use this identifier when calling pollAd to retrieve a preloaded ad for this configuration.

PreloadConfiguration preloadConfiguration

The configuration that dictates how ads are preloaded.

PreloadCallbackV2 preloadCallback

A callback to be invoked when ad availability changes for the given PreloadConfiguration.

Returns
boolean

true if preloading started, false if the preloadId is in-use.