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_100XML Layout Implementation
DefineAdropBanner in XML layout and load it in Activity or Fragment.
1. Define XML Layout
PlaceAdropBanner in a FrameLayout or other container.
activity_main.xml
2. Load in Activity
XML Attributes
| Attribute | Description | Required |
|---|---|---|
app:adrop_unit_id | Ad unit ID | O |
app:adrop_context_id | Context ID for contextual targeting | |
android:layout_width | Banner width (dp) | O |
android:layout_height | Banner height (dp) | O |
Programmatic Implementation
CreateAdropBanner instance directly in code and add it to the view.
AdropBanner Initialization
Constructor
Activity or Application Context
Set Unit ID
Unit ID created in Ad Control Console
Load Ad
Callload() method after adding the banner to the screen to request ads.
Listener Implementation
TheAdropBannerListener interface handles ad lifecycle events.
onAdReceived (Required)
Called when ad is successfully received.onAdFailedToReceive (Required)
Called when ad fails to receive.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 calldestroy() to release resources when the banner is no longer used.
Ad Sizes
Banner ads should have view size matching the unit settings.Common Banner Sizes
| Size | Usage |
|---|---|
| 320 x 50 | Small banner |
| 320 x 100 | Medium banner |
| 16:9 ratio | Video banner |
Specify Size in XML
Specify Size in Code
Test Unit IDs
Use the following test unit IDs during development and testing.| Ad Type | Test Unit ID | Size |
|---|---|---|
| Banner (320x50) | PUBLIC_TEST_UNIT_ID_320_50 | 320 x 50 |
| Banner (320x100) | PUBLIC_TEST_UNIT_ID_320_100 | 320 x 100 |
| Carousel Banner | PUBLIC_TEST_UNIT_ID_CAROUSEL | Variable |
| Banner Video (16:9) | PUBLIC_TEST_UNIT_ID_BANNER_VIDEO_16_9 | 16:9 ratio |
| Banner Video (9:16) | PUBLIC_TEST_UNIT_ID_BANNER_VIDEO_9_16 | 9:16 ratio |
Usage Example
Video Playback Control
For video banner ads, you can manually control video playback usingplay() 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 useuseCustomClick.
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)
UseAdropBanner.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
| Callback | When it fires |
|---|---|
onAdsReceived(banners) | Batch delivered. Each AdropBanner already has the listener attached and its ad data applied. |
onAdsFailedToReceive(errorCode) | Request rejected, network failure, or no fillable ads were returned (ERROR_CODE_AD_NO_FILL). |
onAdClicked / onAdImpression / onAdVideoStart / onAdVideoEnd | Fire on each returned banner just like a single load(). |
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,
onAdsFailedToReceiveis called withERROR_CODE_AD_NO_FILLregardless of backfill configuration. - Do not call
destroy()insideonAdsReceived. Attach each banner to a view hierarchy first, thendestroy()on the parentActivity.onDestroy()(or equivalent). onAdsReceivedfires as soon as ad data is applied, matching the singleload()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 theisBackfilled 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