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
| Size | Description |
|---|---|
| 320x50 | Standard Banner |
| 320x100 | Large Banner |
| 300x250 | Medium Rectangle |
XML Layout Setup
Add a container for the banner in your layout:
<!-- activity_main.xml --><FrameLayoutandroid:id="@+id/bannerContainer"android:layout_width="match_parent"android:layout_height="wrap_content" />
Loading a Banner Ad
- Kotlin
- Java
import net.empower.mobile.ads.api.EMAManagerclass MainActivity : AppCompatActivity() {private lateinit var bannerContainer: FrameLayoutoverride 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.
- Kotlin
- Java
import net.empower.mobile.ads.api.EMAManagerclass 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:
- Kotlin
- Java
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.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.platform.LocalLifecycleOwnerimport net.empower.mobile.ads.compose.EmpowerBannerAd@Composablefun BannerAdSection(modifier: Modifier = Modifier) {val context = LocalContext.currentval lifecycleOwner = LocalLifecycleOwner.currentEmpowerBannerAd(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.
- Kotlin
- Java
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, ...).
- Kotlin
- Java
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)}}}}}
| Method | Description |
|---|---|
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:
- Kotlin
- Java
EMAManager.loadBannerAd(descriptor = this,zoneId = "YOUR_BANNER_ZONE_ID",bannerContainer = bannerContainer,customParameters = "category=sports§ion=news")
Ad Status Reference
| Status | Description |
|---|---|
READY | Banner is loaded and displayed |
FAILED | Banner failed to load |
WILL_LEAVE | User clicked the ad (leaving app) |