---
description: Integrate Auto Load Banners
---

# Auto Load Banner

Auto Load banner placement is our most recent implementation of a banner that serves as a container for banner ads. It is commonly used as a static, constantly shown part of the app’s presentation. The ad content of the banner changes over time depending on the `Refresh Rate` placement setting on [Gravite dashboard](https://dashboard.gravite.net).

### Create Placement <a href="#create-placement" id="create-placement"></a>

To create an instance of [AutoLoadBannerPlacement](https://android-sdk.aatkit.com/references/-a-a-t-kit/com.intentsoftware.addapptr/-auto-load-banner-placement/index.html), use the following API:

{% tabs %}
{% tab title="Java" %}
```java
AutoLoadBannerPlacement placement = AATKit.createAutoLoadBannerPlacement("<PLACEMENT_NAME", BannerPlacementSize.Banner320x53);
```
{% endtab %}

{% tab title="Kotlin" %}
```kotlin
val placement = AATKit.createAutoLoadBannerPlacement("<PLACEMENT_NAME", BannerPlacementSize.Banner320x53)
```
{% endtab %}
{% endtabs %}

You have to specify a placement name and the size argument of the type `BannerPlacementSize` which specifies the size of the ad to be displayed.

### Determine the Appropriate Banner Size <a href="#determine-the-appropriate-banner-size" id="determine-the-appropriate-banner-size"></a>

To ensure you choose the best banner size for a device, use the following API to determine whether the device is a tablet. This information will help you select the optimal banner size for the device type.

{% tabs %}
{% tab title="Java" %}
```java
if (AATKit.isTablet(context)) {
    placement = AATKit.createAutoLoadBannerPlacement("<PLACEMENT_NAME>", BannerPlacementSize.Banner768x90);
} else {
    placement = AATKit.createAutoLoadBannerPlacement("<PLACEMENT_NAME>", BannerPlacementSize.Banner320x50);
}
```
{% endtab %}

{% tab title="Kotlin" %}
```kotlin
if (AATKit.isTablet(context)) {
    placement = AATKit.createAutoLoadBannerPlacement("<PLACEMENT_NAME>", BannerPlacementSize.Banner768x90)
} else {
    placement = AATKit.createAutoLoadBannerPlacement("<PLACEMENT_NAME>", BannerPlacementSize.Banner320x50)
}
```
{% endtab %}
{% endtabs %}

### Listen to Callbacks (Optional) <a href="#listen-to-callbacks-optional" id="listen-to-callbacks-optional"></a>

Through the use of [AutoLoadBannerPlacementListener](https://android-sdk.aatkit.com/references/-a-a-t-kit/com.intentsoftware.addapptr/-auto-load-banner-placement-listener/index.html), you can listen to the different placement callbacks.

{% tabs %}
{% tab title="Java" %}
```java
placement.setListener(this);
```
{% endtab %}

{% tab title="Kotlin" %}
```kotlin
placement.listener = this
```
{% endtab %}
{% endtabs %}

**Autoload Banner Placement Listener**

You will receive different placement callbacks by implementing the `AutoLoadBannerPlacementListener`.

{% tabs %}
{% tab title="Swift" %}
```java
@Override
public void onPauseForAd(@NonNull Placement placement) {
// Ad went fullscreen and that application should pause.
}

@Override
public void onResumeAfterAd(@NonNull Placement placement) {
// Ad came back from fullscreen and that application should resume.
}

@Override
public void onHaveAd(@NonNull Placement placement) {
// The placement has loaded a new ad
}

@Override
public void onNoAd(@NonNull Placement placement) {
// The placement could not load a new ad
}
```
{% endtab %}

{% tab title="Kotlin" %}
```kotlin
override fun onPauseForAd(placement: Placement) {
// Ad went fullscreen and that application should pause.
}

override fun onResumeAfterAd(placement: Placement) {
// Ad came back from fullscreen and that application should resume.
}

override fun onHaveAd(placement: Placement) {
// The placement has loaded a new ad
}

override fun onNoAd(placement: Placement) {
// The placement could not load a new ad
}
```
{% endtab %}
{% endtabs %}

### Get the Banner View

The autoload banner placement provides a banner ad view once and will keep responsible for refreshing the displayed ad content over time. So, once you’ve created the placement, get the ad container view via method `getPlacementView()` and display it on the screen. The placement will update the view content every time it has got a new ad.

{% tabs %}
{% tab title="Java" %}
```java
View bannerView = placement.getPlacementView();
myBannerFrame.addView(bannerView);
```
{% endtab %}

{% tab title="Kotlin" %}
```kotlin
val bannerView = placement.getPlacementView()
myBannerFrame.addView(bannerView)
```
{% endtab %}
{% endtabs %}

### Request Ad

You can load ads for the autoload banner placement automatically.

If you do not set the refresh time interval seconds on the dashboard, AATKit will:

* Reload every 30 seconds.
* respect the refresh time interval setting of the Dashboard (which means, you can configure the interval without having to re-publish your app).

Note: please make sure to disable (or not enable) automatic banner refresh at your ad networks of choice. Otherwise, the different auto reloads would interfere with each other.

{% tabs %}
{% tab title="Java" %}
```java
// reload the banner placement every 30 seconds.
placement.startAutoReload();
```
{% endtab %}

{% tab title="Kotlin" %}
```kotlin
// reload the banner placement every 30 seconds.
placement.startAutoReload()
```
{% endtab %}
{% endtabs %}

The minimum refresh time is 30 seconds.

This needs to stop the auto-reload when it is no longer needed (e.g. if the view controller presenting ads will disappear):

{% tabs %}
{% tab title="Java" %}
```java
placement.stopAutoReload();
```
{% endtab %}

{% tab title="Kotlin" %}
```kotlin
placement.stopAutoReload()
```
{% endtab %}
{% endtabs %}

**One Placement for Multiple Screens**

If the same placement is used on various different pages of the app and you want to load a new ad every time the user navigates to another page, you can achieve that by calling `stopAutoReload()` in the first controller and then call `startAutoReload()` in the next controller. This will immediately load and present a banner ad.

{% tabs %}
{% tab title="Java" %}
```swift
placement.stopAutoReload();
// move to next screen
placement.startAutoReload();
```
{% endtab %}

{% tab title="Kotlin" %}
```kotlin
placement.stopAutoReload();
// move to next screen
placement.startAutoReload();
```
{% endtab %}
{% endtabs %}

### Complete Code Example <a href="#complete-code-example" id="complete-code-example"></a>

{% tabs %}
{% tab title="Java" %}
```java
private AutoLoadBannerPlacement placement = AATKit.createAutoLoadBannerPlacement("<PLACEMENT_NAME>", BannerPlacementSize.Banner320x53);

@Override
protected void onResume() {
    super.onResume();
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityResume(this);

    // Set placement listener to listen to the callbacks
    placement.setListener(this);

    // Get the banner view
    View bannerView = placement.getPlacementView();
    myBannerFrame.addView(bannerView);

    // reload the banner placement every 30 seconds.
    placement.startAutoReload();
}

@Override
protected void onPause() {
    // [IMPORTANT] Stop placement auto-reload
    placement.stopAutoReload();
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityPause(this);
    super.onPause();
}

// AutoLoadBannerPlacementListener implementation
@Override
public void onPauseForAd(@NonNull Placement placement) {
    // App is paused after banner got clicked
}

@Override
public void onResumeAfterAd(@NonNull Placement placement) {
    // Back to the app after clicking on the ad
}

@Override
public void onHaveAd(@NonNull Placement placement) {
    // The placement has loaded a new ad
}

@Override
public void onNoAd(@NonNull Placement placement) {
    // The placement could not load a new ad
}
```
{% endtab %}

{% tab title="Kotlin" %}
```kotlin
private val placement = AATKit.createAutoLoadBannerPlacement("<PLACEMENT_NAME", BannerPlacementSize.Banner320x53)

protected override fun onResume() {
    super.onResume()
    // [IMPORTANT] Notify AATKit about activity lifecycle
    onActivityResume(this)

    // Set placement listener to listen to the callbacks
    placement.listener = this

    // Get the banner view
    val bannerView = placement.getPlacementView()
    myBannerFrame.addView(bannerView)

    // reload the banner placement every 30 seconds.
    placement.startAutoReload()
}

protected override fun onPause() {
    // [IMPORTANT] Stop placement auto-reload
    placement.stopAutoReload()
    // [IMPORTANT] Notify AATKit about activity lifecycle
    onActivityPause(this)
    super.onPause()
}

// AutoLoadBannerPlacementListener implementation
fun onPauseForAd(placement: Placement) {
    // App is paused after banner got clicked
}

fun onResumeAfterAd(placement: Placement) {
    // Back to the app after clicking on the ad
}

fun onHaveAd(placement: Placement) {
    // The placement has loaded a new ad
}

fun onNoAd(placement: Placement) {
    // The placement could not load a new ad
}
```
{% endtab %}
{% endtabs %}
