Skip to main content

Overview

Banner ads are rectangular ads displayed in a portion of the screen. They can be implemented using both XML layout and code.

Key Features

  • Can be fixed at the top, bottom, or middle of the screen
  • Supports image and video ads
  • Supports both XML layout and programmatic implementation
  • Handle ad events through listeners
Use test unit ID during development: PUBLIC_TEST_UNIT_ID_320_100

XML Layout Implementation

Define AdropBanner in XML layout and load it in Activity or Fragment.

1. Define XML Layout

Place AdropBanner in a FrameLayout or other container.
activity_main.xml

2. Load in Activity

XML Attributes


Programmatic Implementation

Create AdropBanner instance directly in code and add it to the view.

AdropBanner Initialization

Constructor

Context
required
Activity or Application Context

Set Unit ID

String
required
Unit ID created in Ad Control Console

Load Ad

Call load() method after adding the banner to the screen to request ads.
Call load() when the banner is visible on screen. Loading when not visible may result in inaccurate impression measurement.

Listener Implementation

The AdropBannerListener interface handles ad lifecycle events.

onAdReceived (Required)

Called when ad is successfully received.

onAdFailedToReceive (Required)

Called when ad fails to receive.
AdropErrorCode
Code indicating error type. See Reference for details.

onAdImpression (Optional)

Called when ad is displayed on screen.

onAdClicked (Required)

Called when user clicks the ad.

onAdVideoStart (Optional)

Called when video playback starts in a video banner ad.

onAdVideoEnd (Optional)

Called when video playback ends in a video banner ad.

Context ID Setting

You can set Context ID for contextual targeting.
Context ID must be set before loading the ad.

Lifecycle Management

destroy()

Always call destroy() to release resources when the banner is no longer used.
Memory leaks may occur if destroy() is not called.

Ad Sizes

Banner ads should have view size matching the unit settings.

Common Banner Sizes

Specify Size in XML

Specify Size in Code


Test Unit IDs

Use the following test unit IDs during development and testing.

Usage Example


Video Playback Control

For video banner ads, you can manually control video playback using play() and pause().

play()

Resumes video playback. Call this when the banner becomes visible again — for example, after a popup is dismissed or the app returns from the background.

pause()

Pauses video playback. Call this when the banner is hidden by a popup or the app enters the background.

Example: Background/Foreground Handling

play() and pause() only affect video banner ads. They have no effect on image banners.

Custom Click Handling

By default, the SDK automatically opens the destination URL when a user clicks the banner ad. If you want to handle click events yourself (e.g., to show a confirmation dialog or track analytics before opening), you can use useCustomClick.
Boolean
default:"false"
When true, the SDK will not automatically open the destination URL on click. Only the onAdClicked event is fired. You must call open() manually to open the destination.

open()

Opens the ad’s destination URL. You can also pass a custom URL to open instead.
open() only works when useCustomClick is set to true. If useCustomClick is false (default), the SDK handles URL opening automatically.

Best Practices

1. Memory Management

Always release the banner when Activity or Fragment is destroyed.

2. Screen Visibility

Load ads when the banner is visible on screen.

3. Error Handling

Implement proper error handling when ad load fails.

4. Using in RecyclerView

Properly manage banners in ViewHolder when using in RecyclerView.

Complete Example

Kotlin Example

Java Example

XML Layout

activity_banner.xml

Batch Loading (loads)

Use AdropBanner.loads() to request multiple banner ads in a single batched call. This is useful for building carousels, paginated feeds, or prefetching a pool of ads.

Signature

Usage

Listener Callbacks

The singular onAdReceived / onAdFailedToReceive callbacks are not invoked on the loads() path. Use onAdsReceived / onAdsFailedToReceive as the sole batch signals.

Constraints

  • Maximum 5 ads per call. If the server returns more, only the first 5 are delivered.
  • Backfill is not applied. If no direct ads fill, onAdsFailedToReceive is called with ERROR_CODE_AD_NO_FILL regardless of backfill configuration.
  • Do not call destroy() inside onAdsReceived. Attach each banner to a view hierarchy first, then destroy() on the parent Activity.onDestroy() (or equivalent).
  • onAdsReceived fires as soon as ad data is applied, matching the single load() contract — the creative paints shortly after attachment.

Backfill Ads

When backfill ads are enabled, backfill ads are automatically loaded when no direct ads are available. You can check if an ad is a backfill ad using the isBackfilled property.
To use backfill ads, you must add the io.adrop:adrop-ads-backfill dependency.

Preloading Backfill Ads (preload)

Starting with SDK 1.17.0, you can use AdropBanner.preload() to preload a backfill banner ad. When a banner that you load() with the same unit ID and the same size gets no direct ad and falls back to a backfill ad, it displays the preloaded ad right away instead of requesting a backfill ad again. load() still requests a direct ad first, regardless of preload. If a direct ad is displayed, the preloaded ad is kept as is. If you don’t call preload, the behavior is the same as before.

Requirements

  • Both io.adrop:adrop-ads and io.adrop:adrop-ads-backfill must be 1.17.0 or later.
  • Preload fetches a backfill ad only when the server has told the app that there are no direct ads to show right now. Otherwise, it ends with ERROR_CODE_AD_PRELOAD_SKIPPED without requesting a backfill ad. This is a normal result in apps that have direct ad campaigns.
  • Right after the app is installed, right after you change the App Key, and right after you switch to a different user with setUID, preload ends with ERROR_CODE_AD_PRELOAD_SKIPPED until the server response arrives.
  • With test unit IDs, preload always ends with ERROR_CODE_AD_PRELOAD_SKIPPED.

Usage

Pass the Activity that will display the banner as context, and call preload right before you open the screen that contains the banner. A preloaded ad is discarded after 30 minutes if it isn’t used, so call preload only for banners you’re about to display. You don’t need to wait for the result before calling load(). If the ad is still being fetched, load() waits for that result and uses it.
To use the preloaded ad, set the adSize of the banner you load() to the same size you passed to preload.

When a Preloaded Ad Is Used

  • Same unit ID and same size: The adSize of the banner you load() (or, if you haven’t set it, the size of the view as laid out on screen, in dp) must match the size you passed to preload. If the size differs, the preloaded ad is kept as is, and load() requests a backfill ad as usual.
  • Same Activity: A preloaded ad isn’t used by a banner created with a different Activity from the one you passed to preload (for example, if you preload in a splash Activity and call load() in the main Activity). When the Activity you passed to preload finishes, the preloaded ad is discarded as well.
  • Used only once: A preloaded ad is gone once a single load() uses it. To preload again, call preload again.
  • Lifetime and count: An ad that isn’t used within 30 minutes is discarded. Only 1 ad is kept per unit and size, and banners keep up to 5 different unit/size combinations. When there are more than 5, ads are discarded starting with the one received first.
  • Calling again: Calling preload again with the same unit and size doesn’t make a new request. If an ad has already been preloaded, onAdPreloadReceived is called without a new request; if one is still being fetched, you get that load’s result (success or failure). You can’t use preload to refresh an ad. However, if the user consent status has changed in the meantime, or if you call it with a different Activity, the existing ad is discarded and a new one is fetched.
  • Consent status changes: If the user consent status changes after an ad is preloaded, that ad isn’t used by load().

Result Callbacks

The following callbacks have been added to AdropBannerListener. Both are optional to implement, and each time you call preload, one of the two is called once on the main thread. No other listener callbacks are called for preload. contextId returns the value you passed to preload as is. It isn’t used to select a preloaded ad.

Failure Codes

Don’t call preload again right away inside the failure callback. If the result doesn’t change — for example, when the backfill dependency is missing — the calls repeat endlessly. Call it again later, such as before you open the next screen.

Next Steps

Native Ads

Implement customizable native ads that match your UI

Interstitial Ads

Implement full-screen interstitial ads

Targeting

Set up user attributes and contextual targeting

Reference

View classes, listeners, and error codes