> For the complete documentation index, see [llms.txt](https://aatkit.gitbook.io/rtbsdk-android-integration/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aatkit.gitbook.io/rtbsdk-android-integration/formats/advanced/separate-loading-and-rendering-of-banner-ads.md).

# Separate Loading and Rendering of Banner Ads

The [RTBBannerAdProvider](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-ad-provider/index.html) gives the app complete control over the lifecycle of a specific banner impression. Specifically, the app can load a banner ad separately from rendering it later. The app can load an ad with a specific configuration and get notified about the outcome of that specific load request via the [RTBBannerAdLoadDelegate](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-ad-load-delegate/index.html). Hence, the usage of the [RTBBannerAdProvider](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-ad-provider/index.html) differs from using [`RTBBannerView`](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-view/index.html).

### Request Ad <a href="#request-a-d" id="request-a-d"></a>

To load a banner ad, you will need to pass an instance of [RTBBannerRequestConfiguration](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-request-configuration/index.html) with `placementID` and the `bundleId`. Please contact our [support](mailto:support@gravite.net) to get the needed IDs.

```kotlin
val configuration = RTBBannerRequestConfiguration(<PLACEMENT_ID>, <BUNDLE_ID>)
configuration.sellerId = "<SELLERID>" // Optional
configuration.bidFloor = <BID_FLOOR>  // Optional
RTBBannerAdProvider.loadBannerAd(context, RTBBannerSize.banner320x50, rtbBannerRequestConfiguration, bannerLoadListener)
```

You will be notified about the loading success or failure through the [RTBBannerAdLoadDelegate](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-request-configuration/index.html) instance passed as `bannerLoadListener`. If the ad loads successfully, you will obtain `RTBBannerBid` instance that can later be used to obtain banner view.

#### Optional - set user targeting <a href="#complete-code-example" id="complete-code-example"></a>

You can pass user targeting data to each request, allowing ads to be more relevant to your audience. Each field in [RTBUserTargeting](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-user-targeting/index.html) is optional.

```kotlin
configuration.userTargeting = RTBUserTargeting(userID = "<USER_ID>", gender = RTBGender.MALE, keywords = listOf("keyword1", "keyword2"), yearOfBirth = 1990)
// yearOfBirth must be a 4-digit number, otherwise it will be ignored
```

### Get Loaded Banner View <a href="#get-loaded-banner-view" id="get-loaded-banner-view"></a>

Once the banner is loaded and the method `bannerAdDidReceiveAd()` is called, you can get the loaded banner view by calling the `RTBBannerAdProvider.getBannerView(context: Context, bannerBid: RTBBannerBid, listener: RTBBannerAdInteractionDelegate?): View` method. You can also pass optional [interactionListener](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-ad-interaction-delegate/index.html) that will be notified about banner events like clicks.

```kotlin
override fun bannerAdDidReceiveAd(bannerBid: RTBBannerBid) {
    // Optionally - examine bid details:
    val priceCPM = bannerBid.priceCPM
    
    val bannerView = RTBBannerAdProvider.getBannerView(context, bannerBid, interactionListner)
    // Add the banner view to the layout
}
```

{% hint style="info" %}
The currency of `bidFloor` and `priceCPM` parameters is USD.
{% endhint %}

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

```kotlin
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Prepare request configurations
        val configuration = RTBBannerRequestConfiguration(<PLACEMENT_ID>, <BUNDLE_ID>)
        configuration.sellerId = "<SELLERID>" // Optional
        configuration.bidFloor = <BID_FLOOR>  // Optional

        // Request a banner ad
        RTBBannerAdProvider.loadBannerAd(this, RTBBannerSize.banner320x50, rtbBannerRequestConfiguration, createBannerLoadDelegate())
    }
    
    private fun createBannerLoadDelegate(): RTBBannerAdLoadDelegate {
        return object : RTBBannerAdLoadDelegate {
            override fun bannerAdDidReceiveAd(bannerBid: RTBBannerBid) {
                // Banner has been loaded
                val banner = RTBBannerAdProvider.getBannerView(this, bannerBid, createInteractionDelegate())
                // Add the banner view to layout
            }

            override fun bannerAdDidFailToReceiveAd(errorMessage: String) {
                // Failed to load a banner ad
            }
        }
    }
    
    private fun createInteractionDelegate(): RTBBannerAdInteractionDelegate {
        return object : RTBBannerAdInteractionDelegate {
            override fun bannerAdDidRecordClick() {
                // The banner received a click
            }

            override fun bannerAdDidPauseForAd() {
                // The app paused after the user clicked on the ad
            }

            override fun bannerAdDidResumeAfterAd() {
                // The app resumed after returning from ad
            }

            override fun bannerAdDidFailToRender(error: String) {
                // Banner failed to render properly
            }
        }
    }

    
}
```

<br>
