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. Zone IDs are configured in the Empower dashboard.

:::note All ad status listeners are optional. The SDK handles ad loading and display automatically. Use listeners only if you need to track ad states for analytics, UI updates, or custom logic. :::


Supported Sizes

SizeDescription
320x50Standard Banner
320x100Large Banner
300x250Medium Rectangle

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 a Banner Ad in a Fragment

When the banner is hosted by a Fragment, pass the Fragment as the descriptor. The SDK will observe the Fragment's view lifecycle so the banner is paused, resumed, and cleaned up correctly across configuration changes and back-stack transitions.

import net.empower.mobile.ads.api.EMAManager
class HomeFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val bannerContainer = view.findViewById<FrameLayout>(R.id.bannerContainer)
EMAManager.loadBannerAd(
descriptor = this,
zoneId = "YOUR_BANNER_ZONE_ID",
bannerContainer = bannerContainer
)
}
}

Listening to Banner Status (Optional)

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 -> { /* Banner is loaded and displayed */ }
AdStatus.FAILED -> { /* Banner failed to load */ }
AdStatus.WILL_LEAVE -> { /* User clicked the ad */ }
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 displaying banner ads inside a RecyclerView, pause and resume the banner's refresh timer based on item visibility to prevent unnecessary ad refreshes while off-screen.

override fun onViewAttachedToWindow(holder: RecyclerView.ViewHolder) {
super.onViewAttachedToWindow(holder)
if (holder is BannerViewHolder) {
holder.zoneId?.let { EMAManager.resumeBannerZone(activity, it) }
}
}
override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) {
super.onViewDetachedFromWindow(holder)
if (holder is BannerViewHolder) {
holder.zoneId?.let { EMAManager.pauseBannerZone(activity, it) }
}
}

Fragment-hosted RecyclerView

If the RecyclerView lives inside a Fragment, pass the Fragment to the pause/resume calls instead of the Activity. The Fragment overloads exist so the descriptor lines up with the one used in loadBannerAd(descriptor = fragment, ...).

class FeedFragment : Fragment() {
inner class FeedAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onViewAttachedToWindow(holder: RecyclerView.ViewHolder) {
super.onViewAttachedToWindow(holder)
if (holder is BannerViewHolder) {
holder.zoneId?.let {
EMAManager.resumeBannerZone(this@FeedFragment, it)
}
}
}
override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) {
super.onViewDetachedFromWindow(holder)
if (holder is BannerViewHolder) {
holder.zoneId?.let {
EMAManager.pauseBannerZone(this@FeedFragment, it)
}
}
}
}
}
MethodDescription
pauseBannerZone(activity, zoneId)Pauses refresh for a banner loaded with an Activity descriptor.
resumeBannerZone(activity, zoneId)Resumes refresh for a banner loaded with an Activity descriptor.
pauseBannerZone(fragment, zoneId)Pauses refresh for a banner loaded with a Fragment descriptor.
resumeBannerZone(fragment, zoneId)Resumes refresh for a banner loaded with a Fragment descriptor.

:::note 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. :::


Custom Targeting Parameters

Pass custom targeting parameters for more relevant ads:

EMAManager.loadBannerAd(
descriptor = this,
zoneId = "YOUR_BANNER_ZONE_ID",
bannerContainer = bannerContainer,
customParameters = "category=sports&section=news"
)

Ad Status Reference

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