بدءًا من الإصدار 21.0.0 من حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة، يمكنك تفعيل ميزة تحسين تهيئة حزمة تطوير البرامج وتحميل الإعلانات لتحسين استجابة الإعلانات بشكل عام والمساعدة في منع حدوث أخطاء "التطبيق لا يستجيب" (ANR) في تطبيقك. يوضّح هذا الدليل التغييرات التي عليك إجراؤها لتفعيل هذه التحسينات.
الإصدار 21.0.0 أو إصدار أحدث من حزمة "SDK لإعلانات Google على الأجهزة الجوّالة"
تعديل ملف البيان
يتوفّر علامتان للتحسين: OPTIMIZE_INITIALIZATION وOPTIMIZE_AD_LOADING. بعد تفعيلها، يتم نقل مهام التحميل والإعداد التي تتطلّب وقت معالجة أطول إلى سلاسل الخلفية.
اتّبِع التعليمات أدناه لإضافة علامات <meta-data> المناسبة في ملف AndroidManifest.xml الخاص بتطبيقك وتفعيل العلامات. يُرجى العِلم أنّه يمكنك تفعيل أحد الخيارَين أو كليهما في التطبيق نفسه.
تحسين عملية إعداد حزمة "SDK لإعلانات Google على الأجهزة الجوّالة"
أفضل طريقة لتحسين عملية الإعداد هي استدعاء
MobileAds.initialize()
في سلسلة محادثات في الخلفية، كما هو موضّح في
دليل البدء.
إذا كنت تفعل ذلك، ليس عليك تفعيل هذا الخيار.
إذا كان عليك استدعاء الطريقة في سلسلة التعليمات الرئيسية، سيؤدي تفعيل العلامة أدناه إلى نقل بعض مهام التهيئة إلى سلسلة التعليمات في الخلفية.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eStarting with Google Mobile Ads SDK version 21.0.0, you can optimize SDK initialization and ad loading to enhance ad responsiveness and mitigate ANR errors.\u003c/p\u003e\n"],["\u003cp\u003eTo enable these optimizations, you need to add specific \u003ccode\u003e<meta-data>\u003c/code\u003e tags to your app's \u003ccode\u003eAndroidManifest.xml\u003c/code\u003e file, controlling initialization and ad loading separately.\u003c/p\u003e\n"],["\u003cp\u003eBy default, both optimization flags (\u003ccode\u003eOPTIMIZE_INITIALIZATION\u003c/code\u003e and \u003ccode\u003eOPTIMIZE_AD_LOADING\u003c/code\u003e) are set to \u003ccode\u003efalse\u003c/code\u003e and require manual activation.\u003c/p\u003e\n"],["\u003cp\u003eOptimizing initialization is best achieved by calling \u003ccode\u003eMobileAds.initialize()\u003c/code\u003e on a background thread; if this is not feasible, enabling the \u003ccode\u003eOPTIMIZE_INITIALIZATION\u003c/code\u003e flag helps by offloading some tasks to a background thread.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eOPTIMIZE_AD_LOADING\u003c/code\u003e flag enhances ad load calls for all ad formats, improving overall ad loading performance.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/ad-manager/mobile-ads-sdk/android/optimize-initialization \"View this page for the Android platform docs.\") [Unity](/ad-manager/mobile-ads-sdk/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](/ad-manager/mobile-ads-sdk/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()`](/ad-manager/mobile-ads-sdk/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](/ad-manager/mobile-ads-sdk/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 ```"]]