# Banners

## Creating a Banner Ad

To create a banner, use the Banner constructor and provide an **Activity context**, **Chartboost location**, **size**, and **BannerCallback**. A banner ad contains a `BannerSize` which corresponds to the following:

| Name        | Field                    | Size      |
| :---------- | :----------------------- | :-------- |
| Standard    | `BannerSize.STANDARD`    | 320 x 50  |
| Medium      | `BannerSize.MEDIUM`      | 300 x 250 |
| Leaderboard | `BannerSize.LEADERBOARD` | 728 x 90  |

Example:

```kotlin
val chartboostBanner = Banner(
    context = context,
    location = "location",
    size = BannerSize.STANDARD,
    callback = BannerCallbackImpl(),
    mediation = null
)
```
```java
Banner chartboostBanner = new Banner(context, "location", Banner.BannerSize.STANDARD, bannerCallback, null);
```

Chartboost’s banner extends Android View and thus can be added programmatically to your Android view layout.

After you’ve confirmed the ad has been loaded (preferably using the `BannerCallback` you had to provide in the banner constructor, see below for more details), you can call `show()` on the banner instance to actually show the banner ad.


- We do not serve banner ads to apps that are opted-out of [behavioral targeting](/en/faq/coppa/).
- You do not need to create a **Banner Publishing Campaign** on the Chartboost Dashboard. The banner ads are delivered through our **Exchange**. You only need to call on them via the SDK.
- Your **banner analytics** are available in the **App Analytics** section of your Chartboost Dashboard.
- Multiple banners can be displayed at once if desired.
- Banner ads are limited to Android SDKs version 8.0.1 and above.
- ChartboostBanner is a View subclass able to show banner ads. Unlike other ad types, the  developer is responsible for integrating the banner with the app UI and presenting it to the user.



## Showing Banner Ads

Every banner has a callback which must be provided when instantiating a new Banner. It gets notified by events related to the banner life-cycle by implementing the `BannerCallback` interface methods. The main method you should take into consideration is `onAdLoaded()`, which will inform the callback asynchronously when the ad is ready to be displayed. A typical implementation would be as follows.

<ul class="tab" data-tab="7a39b0df-af35-463a-a27a-0ea72a0dc595" data-name="showBannerAds">
  
      <li class="active">
          <a href="#">Kotlin </a>
      </li>
  
      <li>
          <a href="#">Java </a>
      </li>
  
</ul>
<ul class="tab-content" id="7a39b0df-af35-463a-a27a-0ea72a0dc595" data-name="showBannerAds">
  
      <li class="active">
<div class="language-kotlin highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">override</span> <span class="k">fun</span> <span class="nf">onAdLoaded</span><span class="p">(</span><span class="n">cacheEvent</span><span class="p">:</span> <span class="nc">CacheEvent</span><span class="p">,</span> <span class="n">cacheError</span><span class="p">:</span> <span class="nc">CacheError</span><span class="p">?)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">cacheError</span> <span class="p">!=</span> <span class="k">null</span><span class="p">)</span> <span class="p">{</span>
        <span class="cm">/* Handle error */</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
        <span class="n">chartboostBanner</span><span class="p">.</span><span class="nf">show</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>
</li>
  
      <li>
<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">public</span> <span class="kt">void</span> <span class="nf">onAdLoaded</span><span class="o">(</span><span class="nc">CacheEvent</span> <span class="n">cacheEvent</span><span class="o">,</span> <span class="nd">@Nullable</span> <span class="nc">CacheError</span> <span class="n">cacheError</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span> <span class="o">(</span><span class="n">cacheError</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
        <span class="cm">/* Handle error */</span>
    <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
        <span class="n">chartboostBanner</span><span class="o">.</span><span class="na">show</span><span class="o">();</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>
</li>
  
</ul>


For a more detailed demo, please [refer to our Java sample application](https://github.com/ChartBoost/android-sdk-sample-java).



## Ad Identifier

All the non-error event objects passed as parameters in delegate method calls include an `adID` property.

This is a string that uniquely identifies a cached ad. It might help when working with Chartboost to identify faulty creatives.

