Để thảo luận và đưa ra ý kiến phản hồi về các sản phẩm của chúng tôi, hãy tham gia kênh Discord chính thức của AdMob trong máy chủ Cộng đồng quảng cáo và đo lường của Google.
Kể từ SDK Quảng cáo trên thiết bị di động của Google (GMA) phiên bản 21.0.0, bạn có thể bật tính năng khởi chạy SDK và tải quảng cáo được tối ưu hoá để cải thiện khả năng phản hồi tổng thể của quảng cáo và giúp ngăn chặn lỗi "Ứng dụng không phản hồi" (ANR) trên ứng dụng của bạn. Hướng dẫn này trình bày những thay đổi mà bạn cần thực hiện để bật các hoạt động tối ưu hoá này.
SDK quảng cáo trên thiết bị di động của Google phiên bản 21.0.0 trở lên.
Cập nhật tệp kê khai
Hiện có 2 loại cờ tối ưu hoá: OPTIMIZE_INITIALIZATION và OPTIMIZE_AD_LOADING. Sau khi được bật, những hoạt động khởi chạy và tải quảng cáo cần nhiều thời gian xử lý hơn sẽ được chuyển bớt sang các luồng ở chế độ nền.
Làm theo hướng dẫn ở bên dưới để thêm các thẻ <meta-data> tương ứng vào tệp AndroidManifest.xml của ứng dụng và bật cờ. Xin lưu ý rằng bạn có thể bật một hoặc cả hai loại cờ trong cùng một ứng dụng.
Tối ưu hoá hoạt động khởi chạy SDK quảng cáo trên thiết bị di động của Google
Cách tối ưu hoá quy trình khởi chạy hiệu quả nhất là gọi MobileAds.initialize() trên một luồng nền, như mô tả trong Hướng dẫn bắt đầu.
Nếu đã làm như vậy, bạn không cần bật cờ này.
Nếu bạn phải gọi phương thức trên luồng chính, việc bật cờ bên dưới sẽ di chuyển một số tác vụ khởi tạo sang luồng nền.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\u003cp\u003eStarting with Google Mobile Ads SDK version 21.0.0, new optimization features enhance ad responsiveness and reduce "Application Not Responding" errors.\u003c/p\u003e\n"],["\u003cp\u003eTwo optimization flags, \u003ccode\u003eOPTIMIZE_INITIALIZATION\u003c/code\u003e and \u003ccode\u003eOPTIMIZE_AD_LOADING\u003c/code\u003e, offload time-consuming tasks to background threads.\u003c/p\u003e\n"],["\u003cp\u003eYou can enable either or both flags in your app's \u003ccode\u003eAndroidManifest.xml\u003c/code\u003e to optimize SDK initialization and ad loading.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eOPTIMIZE_INITIALIZATION\u003c/code\u003e flag is most effective when \u003ccode\u003eMobileAds.initialize()\u003c/code\u003e is called on the main thread; otherwise, background initialization is already recommended.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eOPTIMIZE_AD_LOADING\u003c/code\u003e flag enhances ad loading for all ad formats by shifting processing to background threads.\u003c/p\u003e\n"]]],["To optimize Google Mobile Ads SDK, enable `OPTIMIZE_INITIALIZATION` and/or `OPTIMIZE_AD_LOADING` flags in your `AndroidManifest.xml`. These flags move time-consuming initialization and ad loading tasks to background threads, improving app responsiveness and preventing ANR errors. Add `\u003cmeta-data\u003e` tags within the `\u003capplication\u003e` tag, setting the desired flag's value to \"true.\" SDK version 21.0.0 or higher is required, with both flags being false by default.\n"],null,["Select platform: [Android](/admob/android/optimize-initialization \"View this page for the Android platform docs.\") [Unity](/admob/unity/optimize-initialization \"View this page for the Unity platform docs.\")\n\n\u003cbr /\u003e\n\nStarting from Google Mobile Ads (GMA) SDK version 21.0.0, you can enable\noptimized SDK initialization and ad loading to improve the overall\nresponsiveness of ads and help prevent [\"Application Not Responding\"\n(ANR)](//developer.android.com/topic/performance/vitals/anr) errors on your app.\nThis guide outlines the changes you need to make to enable these optimizations.\n\nRequirements\n\n- Complete the [Get Started guide](/admob/android/quick-start).\n\n\u003c!-- --\u003e\n\n- Google Mobile Ads SDK version 21.0.0 or higher.\n\nUpdate your manifest file\n\nThere are two optimization flags available: `OPTIMIZE_INITIALIZATION` and\n`OPTIMIZE_AD_LOADING`. Once they're turned on, the initialization and ad\nloading tasks that require extended processing time are offloaded to\nbackground threads.\n\nFollow the instructions below to add the corresponding `\u003cmeta-data\u003e` tags in\nyour app's `AndroidManifest.xml` file and turn on the flags. Note that you can\nturn on one or both options in the same app.\n| **Important:** Starting with Google Mobile Ads SDK 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.\n\nOptimize Google Mobile Ads SDK initialization\n\n: The best way to optimize initialization is to call\n [`MobileAds.initialize()`](/admob/android/reference/com/google/android/gms/ads/MobileAds#initialize(android.content.Context,com.google.android.gms.ads.initialization.OnInitializationCompleteListener))\n on a background thread, as described in the\n [Get Started guide](/admob/android/quick-start#initialize_the_mobile_ads_sdk).\n If you are already doing so, you don't need to enable this flag.\n\n If you must call the method on the main thread, enabling the flag below will\n move some of the initialization tasks to the background thread. \n\n ```scdoc\n \u003cmanifest\u003e\n ...\n \u003capplication\u003e\n ...\n \u003cmeta-data\n android:name=\"com.google.android.gms.ads.flag.OPTIMIZE_INITIALIZATION\"\n android:value=\"true\"/\u003e\n \u003c/application\u003e\n \u003c/manifest\u003e\n ```\n\nOptimize ad loading\n\n: The flag below optimizes ad load calls for all ad formats:\n\n ```scdoc\n \u003cmanifest\u003e\n ...\n \u003capplication\u003e\n ...\n \u003cmeta-data\n android:name=\"com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING\"\n android:value=\"true\"/\u003e\n \u003c/application\u003e\n \u003c/manifest\u003e\n ```"]]