<br />

Starting from Google Mobile Ads (GMA) SDK version 21.0.0, you can enable
optimized SDK initialization and ad loading to improve the overall
responsiveness of ads and help prevent ["Application Not Responding"
(ANR)](https://developer.android.com/topic/performance/vitals/anr) errors on your app.
This guide outlines the changes you need to make to enable these optimizations.

## Requirements

Before you continue, [set up Google Mobile Ads SDK (Legacy)](https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start.md.txt).

- Google Mobile Ads SDK (Legacy) version 21.0.0 or higher.

## Update your manifest file

There are two optimization flags available: `OPTIMIZE_INITIALIZATION` and
`OPTIMIZE_AD_LOADING`. Once they're turned on, the initialization and ad
loading tasks that require extended processing time are offloaded to
background threads.

Follow the instructions below to add the corresponding `<meta-data>` tags in
your app's `AndroidManifest.xml` file and turn on the flags. Note that you can
turn on one or both options in the same app.

> [!IMPORTANT]
> **Important:** Starting with Google Mobile Ads SDK (Legacy) version 24.0.0, the `OPTIMIZE_INITIALIZATION` and `OPTIMIZE_AD_LOADING` flags are set to `true` by default. In versions prior to 24.0.0, these flags are set to `false` by default.

Optimize Google Mobile Ads SDK (Legacy) initialization

:   The best way to optimize initialization is to call
    [`MobileAds.initialize()`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/MobileAds.md.txt#initialize(android.content.Context,com.google.android.gms.ads.initialization.OnInitializationCompleteListener))
    on a background thread, as described in the
    [Get Started guide](https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start.md.txt#initialize_the_mobile_ads_sdk).
    If you are already doing so, you don't need to enable this flag.

    If you must call the method on the main thread, enabling the flag below will
    move some of the initialization tasks to the background thread.

    ```
    <manifest>
      ...
      <application>
          ...
          <meta-data
              android:name="com.google.android.gms.ads.flag.OPTIMIZE_INITIALIZATION"
              android:value="true"/>
      </application>
    </manifest>
    ```

Optimize ad loading

:   The flag below optimizes ad load calls for all ad formats:

    ```
    <manifest>
      ...
      <application>
          ...
          <meta-data
              android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
              android:value="true"/>
      </application>
    </manifest>
    ```