Skip to main content

Banner Ads

Banner ads are rectangular ads that occupy a portion of your app's layout. They can refresh automatically and stay on screen while users interact with your app.

Each ad format uses a Zone ID to identify the ad placement. Banners are served in the standard sizes; the size of each zone is configured in the Empower dashboard.


XML Layout Setup

Add a container for the banner in your layout:

activity_main.xml
<FrameLayout
android:id="@+id/bannerContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

Loading a Banner Ad

import net.empower.mobile.ads.api.EMAManager

class MainActivity : AppCompatActivity() {
private lateinit var bannerContainer: FrameLayout

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

bannerContainer = findViewById(R.id.bannerContainer)

EMAManager.loadBannerAd(
descriptor = this,
zoneId = "YOUR_BANNER_ZONE_ID",
bannerContainer = bannerContainer
)
}
}
Loading from a Fragment

When the banner lives in a Fragment, pass the Fragment as the descriptor instead of the Activity. The SDK follows the descriptor's lifecycle to manage the banner correctly.


Listening to Banner Status

The SDK handles loading, retries, and refreshes

All ad status listeners are optional. The SDK loads and displays ads automatically, retries failed loads, and refreshes banners on schedule based on per-zone settings from the Empower dashboard. Do not build manual reload loops, for example calling loadBannerAd again when a load fails. Use listeners only if you need to track ad states for analytics, UI updates.

StatusDescription
READYBanner is loaded and displayed
FAILEDBanner failed to load
WILL_LEAVEUser clicked the ad (leaving app)

If you need to track banner status for analytics or UI updates:

EMAManager.loadBannerAd(
descriptor = this,
zoneId = "YOUR_BANNER_ZONE_ID",
bannerContainer = bannerContainer,
listener = object : AdStatusListener {
override fun bannerStatusChanged(status: AdStatus, zoneId: String, adUnitId: String) {
when (status) {
AdStatus.READY -> { }
AdStatus.FAILED -> { }
AdStatus.WILL_LEAVE -> { }
else -> {}
}
}
}
)

Jetpack Compose

For apps using Jetpack Compose, use the EmpowerBannerAd composable:

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import net.empower.mobile.ads.compose.EmpowerBannerAd

@Composable
fun BannerAdSection(modifier: Modifier = Modifier) {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current

EmpowerBannerAd(
modifier = modifier,
zoneId = "YOUR_BANNER_ZONE_ID",
context = context,
lifecycleOwner = lifecycleOwner
)
}

RecyclerView Usage (Pause & Resume)

When a banner row scrolls off screen inside a RecyclerView, pause its refresh timer and resume it when the row comes back. Use your adapter's attach and detach callbacks:

override fun onViewAttachedToWindow(holder: RecyclerView.ViewHolder) {
super.onViewAttachedToWindow(holder)
if (holder.itemViewType == AD_VIEW_TYPE) {
EMAManager.resumeBannerZone(activity, "YOUR_BANNER_ZONE_ID")
}
}

override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) {
super.onViewDetachedFromWindow(holder)
if (holder.itemViewType == AD_VIEW_TYPE) {
EMAManager.pauseBannerZone(activity, "YOUR_BANNER_ZONE_ID")
}
}
warning

The descriptor passed to pauseBannerZone / resumeBannerZone must match the one used in loadBannerAd. Passing an Activity for a banner that was loaded with a Fragment (or vice-versa) is a silent no-op.