Select platform: [Android (beta)
![New](https://developers.google.com/static/admob/images/new.svg)](https://developers.google.com/admob/android/next-gen/native "View this page for the Android (beta) platform docs.") [Android](https://developers.google.com/admob/android/native "View this page for the Android platform docs.") [iOS](https://developers.google.com/admob/ios/native "View this page for the iOS platform docs.") [Flutter](https://developers.google.com/admob/flutter/native "View this page for the Flutter platform docs.") [Unity](https://developers.google.com/admob/unity/native-overlay "View this page for the Unity platform docs.")

<br />

![](https://developers.google.com/static/admob/images/format-native.svg)

Native ads are ad assets that are presented to users through UI components that
are native to the platform. They're shown using the same types of views with
which you're already building your layouts, and can be formatted to match your
app's visual design.

When a native ad loads, your app receives an ad object that contains its assets,
and the app---rather than Google Mobile Ads SDK---is then
responsible for displaying them.

Broadly speaking, there are two parts to successfully implementing native ads:
Loading an ad using the SDK and then displaying the ad content in your app.

This page shows how to use the SDK to load

[native ads](https://support.google.com/admob/answer/7187428).


Tip: Learn more about native ads in our [Native Ads
Playbook](https://admob.google.com/home/resources/native-ads-playbook/).

You can also check out some customer success stories:
[case study 1](https://admob.google.com/home/resources/alarmmon-achieves-higher-rpm-with-admob-triggered-native-ads/),
[case study 2](https://admob.google.com/home/resources/linghit-limited-doubles-ad-revenue-with-admob-native-ads/).


## Prerequisites

- Complete the [Get started guide](https://developers.google.com/admob/android/quick-start).

## Always test with test ads

When building and testing your apps, make sure you use test ads rather than
live, production ads.

The easiest way to load test ads is to use our dedicated test ad unit ID
for native ads on Android:

`ca-app-pub-3940256099942544/2247696110`

It's been specially configured to return test ads for every request, and you can
use it in your own apps while coding, testing, and debugging. Just make sure you
replace it with your own ad unit ID before publishing your app.

For details on Google Mobile Ads SDK test ads, see
[Enable test ads](https://developers.google.com/admob/android/test-ads).

## Load ads

Native ads are loaded with the
[`AdLoader`](https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdLoader) class,
which has its own
[`Builder`](https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdLoader.Builder)
class to customize it during creation. By adding listeners to the `AdLoader`
when building it, an app specifies which types of native ads it is ready to
receive. The `AdLoader` then requests just those types.

### Build an AdLoader

The following code demonstrates how to build an `AdLoader` that can load native
ads:  

### Java

    // It is recommended to call AdLoader.Builder on a background thread.
    new Thread(
            () -> {
              AdLoader adLoader =
                  new AdLoader.Builder(context, "<var translate="no">AD_UNIT_ID</var>")
                      .forNativeAd(
                          new NativeAd.OnNativeAdLoadedListener() {
                            @Override
                            // The native ad loaded successfully. You can show the ad.
                            public void onNativeAdLoaded(@NonNull NativeAd nativeAd) {}
                          })
                      .withAdListener(
                          new AdListener() {
                            @Override
                            // The native ad load failed. Check the adError message for failure
                            // reasons.
                            public void onAdFailedToLoad(@NonNull LoadAdError adError) {}
                          })
                      // Use the NativeAdOptions.Builder class to specify individual options
                      // settings.
                      .withNativeAdOptions(new NativeAdOptions.Builder().build())
                      .build();
            })
        .start();  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.java#L41-L64

### Kotlin

    // It is recommended to call AdLoader.Builder on a background thread.
    CoroutineScope(Dispatchers.IO).launch {
      val adLoader =
        AdLoader.Builder(context, "<var translate="no">AD_UNIT_ID</var>")
          .forNativeAd { nativeAd ->
            // The native ad loaded successfully. You can show the ad.
          }
          .withAdListener(
            object : AdListener() {
              override fun onAdFailedToLoad(adError: LoadAdError) {
                // The native ad load failed. Check the adError message for failure reasons.
              }
            }
          )
          // Use the NativeAdOptions.Builder class to specify individual options settings.
          .withNativeAdOptions(NativeAdOptions.Builder().build())
          .build()
    }  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.kt#L34-L51

Replace <var translate="no">AD_UNIT_ID</var> with your test device ID.
| **Warning:** Attempting to load a new ad from the `onAdFailedToLoad()` method is strongly discouraged. If you must load an ad from `onAdFailedToLoad()`, limit ad load retries to avoid continuous failed ad requests in situations such as limited network connectivity.

The
[`forNativeAd()`](https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdLoader.Builder#forNativeAd(com.google.android.gms.ads.nativead.NativeAd.OnNativeAdLoadedListener))
method is responsible for preparing the `AdLoader` for the `NativeAd` format.
When an ad has loaded successfully, the listener object's `onNativeAdLoaded()`
method is called.

### Set up an AdListener with the AdLoader (optional)

When creating the `AdLoader`, the
[`withAdListener`](https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdLoader.Builder#withAdListener(com.google.android.gms.ads.AdListener))
function sets an
[`AdListener`](https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdListener) for the
loader. The method takes an `AdListener` as its lone parameter, which receives
callbacks from the `AdLoader` when ad lifecycle events take place:  

### Java

    adLoaderBuilder.withAdListener(
        // Override AdListener callbacks here.
        new AdListener() {});  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.java#L70-L72

### Kotlin

    adLoaderBuilder.withAdListener(
      // Override AdListener callbacks here.
      object : AdListener() {}
    )  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.kt#L57-L60

### Request ads


| **Tip:** You can use ad load calls to build up a cache of preloaded ads before you intend to show them, so that ads can be shown with zero latency when needed. Since ads expire after an hour, you should clear this cache and reload with new ads every hour.

<br />

Once you've finished building an `AdLoader`, it's time to use it to request ads.
There are two methods available for this: `loadAd()` and `loadAds()`.
| **Key Point:** The `loadAds()` method works only with Google ads. For mediated ads, use `loadAd()` instead.

#### `loadAd()`

This method sends a request for a single ad.  

### Java

    adLoader.loadAd(new AdRequest.Builder().build());  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.java#L78-L78

### Kotlin

    adLoader.loadAd(AdRequest.Builder().build())  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.kt#L66-L66

#### `loadAds()`

This method sends a request for multiple ads (up to five):  

### Java

    // Load three native ads.
    adLoader.loadAds(new AdRequest.Builder().build(), 3);  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.java#L90-L91

### Kotlin

    // Load three native ads.
    adLoader.loadAds(AdRequest.Builder().build(), 3)  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.kt#L78-L79

Both methods take an
[`AdRequest`](https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdRequest)
object as their first parameter. This is the same
`AdRequest` class used by banners and interstitials,
and you can use methods of the `AdRequest` class to
add [targeting information](https://developers.google.com/admob/android/targeting), just as
you would with other ad formats.

#### Load multiple ads (optional)

The `loadAds()` method takes an additional parameter: the number of ads the SDK
should attempt to load for the request. This number is capped at five, and it's
not guaranteed that the SDK will return the exact number of ads requested.

Returned Google ads will all be different from each other, though ads from
reserved inventory or third-party buyers are not guaranteed to be unique.

Don't use the `loadAds()` method if you're using mediation, as requests for
multiple native ads don't work for ad unit IDs that have been
configured for mediation.

#### Callbacks

After a call to `loadAd()`, a single callback is made to the previously defined
[listener methods](https://developers.google.com/admob/android/native#build) to deliver the native ad object or report an error.

After a call to `loadAds()`, multiple such callbacks are made (at least one,
and no more than the number of ads requested). Apps requesting multiple ads
should call `AdLoader.isLoading()` in their callback implementations to
determine whether the loading process has finished.

Here's an example showing how to check `isLoading()` in the
`onNativeAdLoaded()` callback:  

### Java

    adLoaderBuilder
        .forNativeAd(
            nativeAd -> {
              // This callback is invoked when a native ad is successfully loaded.
            })
        .build();  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.java#L104-L109

### Kotlin

    adLoaderBuilder
      .forNativeAd { nativeAd ->
        // This callback is invoked when a native ad is successfully loaded.
      }
      .build()  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.kt#L92-L96

### Release resources

Be sure to use the `destroy()` method on loaded native ads. This releases
utilized resources and prevents memory leaks.
| **Key Point:** `destroy()` must be called on **all ads**, even if they weren't used or referenced.

Verify that all `NativeAd` references are destroyed in your activity's
`onDestroy()` method.

In your `onNativeAdLoaded` callback, make sure to destroy any existing
native ads that will be dereferenced.

Another key check is if the activity is destroyed and if so, call `destroy()` on
the returned ad and return immediately:  

### Java

    nativeAd.destroy();  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.java#L115-L115

### Kotlin

    nativeAd.destroy()  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeAdSnippets.kt#L102-L102

### Best practices

Follow these rules when loading ads.

- Apps that use native ads in a list should precache the list of ads.

- When precaching ads, clear your cache and reload after one hour.

<!-- -->

- Don't call `loadAd()` or `loadAds()` on an `AdLoader` until the first request finishes loading.

<!-- -->

- Limit native ad caching to only what is needed. For example when precaching,
  only cache the ads that are immediately visible on the screen. Native ads
  have a large memory footprint, and caching native ads without destroying them
  results in excessive memory use.

- Destroy native ads when no longer in use.

## Hardware acceleration for video ads

In order for video ads to show successfully in your native ad views,
[hardware
acceleration](https://developer.android.com/guide/topics/graphics/hardware-accel)
must be enabled.

Hardware acceleration is enabled by default, but some apps may choose to
disable it. If this applies to your app, we recommend enabling hardware
acceleration for Activity classes that use ads.

#### Enabling hardware acceleration

If your app does not behave properly with hardware acceleration turned on
globally, you can control it for individual activities as well. To enable or
disable hardware acceleration, use the `android:hardwareAccelerated` attribute
for the
[`<application>`](https://developer.android.com/guide/topics/manifest/application-element)
and
[`<activity>`](https://developer.android.com/guide/topics/manifest/activity-element)
elements in your `AndroidManifest.xml`. The following example enables hardware
acceleration for the entire app but disables it for one activity:  

    <application android:hardwareAccelerated="true">
        <!-- For activities that use ads, hardwareAcceleration should be true. -->
        <activity android:hardwareAccelerated="true" />
        <!-- For activities that don't use ads, hardwareAcceleration can be false. -->
        <activity android:hardwareAccelerated="false" />
    </application>  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/HardwareAccelerationSnippet.xml

See the [HW acceleration
guide](https://developer.android.com/guide/topics/graphics/hardware-accel) for
more information about options for controlling hardware acceleration. Note
that individual ad views cannot be enabled for hardware acceleration if the
Activity is disabled, so the Activity itself must have hardware acceleration
enabled.

## Display your ad

Once you have loaded an ad, all that remains is to display it to your users.
Head over to our [Native Advanced
guide](https://developers.google.com/admob/android/native/advanced) to see how.