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.

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