> For the complete documentation index, see [llms.txt](https://docs.bidapp.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bidapp.io/integration/android/banner-ads.md).

# Banner Ads

To load a banner, create a `BannerView` and add it as a subview of your view hierarchy.

You can create banners of either **320x50** or **300x250** size:

{% tabs %}
{% tab title="Java" %}

```java
//add banners to view

public void addBanner_320x50_to_view(View view, BannerViewDelegate delegate) {
    BannerView banner = new BannerView(Activity activity).banner(AdFormat.banner_320x50);
    banner.setBannerViewDelegate(bannerShowDelegate)
    view.addView(banner);
}

public void addBanner_300x250_to_view(View view, BannerViewDelegate delegate) {
    BannerView banner = new BannerView(Activity activity).banner(AdFormat.banner_300x250);
    banner.setBannerViewDelegate(bannerShowDelegate)
    view.addView(banner);
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
//add banners to view 

fun addBanner_320x50_to_view(view:View) {
    val banner = BannerView(activity:Activity).banner(AdFormat.banner_320x50)
    banner.setBannerViewDelegate(bannerShowDelegate)
    view.addView(banner)
}

fun addBanner_300x250_to_view(view:View) {
    val banner = BannerView(activity:Activity).banner(AdFormat.banner_300x250)
    banner.setBannerViewDelegate(bannerShowDelegate)
    view.addView(banner)
}
```

{% endtab %}
{% endtabs %}

Implement `BannerViewDelegate` so that you are notified of when your ad is ready and of other ad-related events.

{% tabs %}
{% tab title="Java" %}

```java
//BannerViewDelegate protocol methods 

@Override
public void adViewDidLoadAd(BannerView adView, @NonNull AdInfo adInfo) {
    System.out.println("Banner - adViewDidLoadAd. AdView: " + adView + ", AdInfo: " + adInfo);
}

@Override
public void adViewDidDisplayAd(@NonNull BannerView adView, @NonNull AdInfo adInfo) {
    System.out.println("Banner - didDisplayAd. AdView: " + adView + ", AdInfo: " + adInfo);
}

@Override
public void adViewDidFailToDisplayAd(@NonNull BannerView adView, @NonNull AdInfo adInfo, Error errors) {
    System.out.println("Banner - didFailToDisplayAd. AdView: " + adView + ", Error: " + errors.getLocalizedMessage());
}

@Override
public void adViewClicked(@NonNull BannerView adView, @NonNull AdInfo adInfo) {
    System.out.println("Banner - didClicked. AdView: " + adView + ", AdInfo: " + adInfo);
}

@Override
public void allNetworksFailedToDisplayAd(@NonNull BannerView adView) {
    System.out.println("Banner - allNetworksFailedToDisplayAd. AdView: " + adView );
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
//BannerViewDelegate protocol methods 

override fun adViewDidLoadAd(adView: BannerView, adInfo: AdInfo) {
    print("Banner - adViewDidLoadAd. AdView: $adView, AdInfo: $adInfo")
}

override fun adViewDidDisplayAd(adView: BannerView, adInfo: AdInfo) {
    print("Banner - didDisplayAd. AdView: $adView, AdInfo: $adInfo")
}

override fun adViewDidFailToDisplayAd(adView: BannerView, adInfo: AdInfo, errors: Error) {
    print("Banner - didFailToDisplayAd. AdView: $adView, Error:${errors.localizedMessage}")
}

override fun adViewClicked(adView: BannerView, adInfo: AdInfo) {
    print("Banner - didClicked. AdView: $adView, AdInfo: $adInfo")
}

override fun allNetworksFailedToDisplayAd(adView: BannerView) {
    print("Banner - allNetworksFailedToDisplayAd")
}
```

{% endtab %}
{% endtabs %}

## Banner State

To determine whether an advertisement banner is currently being displayed or not you can use function, that returns a boolean value, specifically **`true`** if an ad is present and visible on the screen, and **`false`** otherwise:

{% tabs %}
{% tab title="Java" %}

```java
banner.isAdDisplayed()
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
banner.isAdDisplayed()
```

{% endtab %}
{% endtabs %}

To check whether the SDK is initialized and if the banner is ready for display or not you can use function, that returns a boolean value (**`true`** if the conditions are met and **`false`** otherwise).

{% tabs %}
{% tab title="Java" %}

```java
banner.isReadyToRefresh()
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
banner.isReadyToRefresh()
```

{% endtab %}
{% endtabs %}

## Stopping and Starting Auto-Refresh

There may be cases when you would like to stop auto-refresh, for instance, when you hide a banner ad or want to manually refresh.&#x20;

Stop auto-refresh for a banner ad with the following code:

{% tabs %}
{% tab title="Java" %}

```java
banner.stopAutorefresh()
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
banner.stopAutorefresh()
```

{% endtab %}
{% endtabs %}

Start auto-refresh for a banner ad with the following code:

{% tabs %}
{% tab title="Java" %}

```java
banner.startAutorefresh(30.0)
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
banner.startAutorefresh(30.0)
```

{% endtab %}
{% endtabs %}

Manually refresh the contents with the following code. You must stop auto-refresh prior to calling `refreshAd`.

{% tabs %}
{% tab title="Java" %}

```java
banner.refreshAd()
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
banner.refreshAd()
```

{% endtab %}
{% endtabs %}

## Destroying Banners

Once you're finished with a banner ad, it's essential to clean up its resources by invoking the destroy() method. Neglecting this step could lead to a deterioration in your app's performance

{% tabs %}
{% tab title="Java" %}

```java
banner.destroy()
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
banner.destroy()
```

{% endtab %}
{% endtabs %}
