ปรับปรุงเวลาในการโหลด IMA
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
IMA SDK จะโหลดทรัพยากร Dependency เพื่อขอโฆษณา วัดการมองเห็นโฆษณา และ
รายงานการแสดงโฆษณา การเริ่มต้น IMA ก่อนที่จะส่งคำขอโฆษณาจะช่วยให้คุณมีเวลาโหลดทรัพยากร Dependency ของ IMA มากที่สุดก่อนการเล่นโฆษณา หน้านี้ครอบคลุม
วิธีจัดการเวลาในการโหลด IMA ในแอป
โทรหา ImaSdkFactory.initialize()
เมธอด
ImaSdkFactory.initialize()
จะเริ่มโหลดทรัพยากร SDK ล่วงหน้าก่อนคำขอโฆษณารายการแรก หากต้องการใช้ initialize()
คุณต้องมี IMA เวอร์ชัน 3.35.1 ขึ้นไป
เรียกใช้ ImaSdkFactory.initialize()
เมื่อแอปพลิเคชันเริ่มต้น หรือในช่วงต้นของวงจร
แอปพลิเคชันตามที่โครงสร้างแอปของคุณอนุญาต การเรียก initialize()
ใช้พารามิเตอร์ต่อไปนี้
context
: ใช้บริบทของแอปพลิเคชัน ซึ่งพร้อมใช้งานเสมอในวงจรของแอปพลิเคชัน
settings
: ส่งออบเจ็กต์
ImaSdkSettings
พร้อมค่าที่ตั้งไว้ การตั้งค่า IMA ที่ใช้ในคําสั่งเรียก initialize()
ต้องเหมือนกับค่าการตั้งค่าที่ใช้ในคําสั่งเรียก createAdsLoader()
IMA SDK ใช้การตั้งค่าเหล่านี้ โดยเฉพาะการตั้งค่าภาษา
สำหรับคีย์แคช เราไม่แนะนำให้ใช้ค่าทดสอบหรือค่าปลอมสำหรับการตั้งค่า
ที่ใช้ในการเรียกเมธอด initialize()
เนื่องจากอาจเกิดการพลาดแคชและ
เพิ่มเวลาในการโหลดโฆษณา
นำอินสแตนซ์ AdsLoader
กลับมาใช้ซ้ำ
เราขอแนะนำให้คุณใช้AdsLoader
อินสแตนซ์เดิมซ้ำเพื่อปรับปรุงเวลาในการโหลด IMA AdsLoader
อินเทอร์เฟซสามารถจัดการคำขอโฆษณาหรือสตรีมหลายรายการได้
หลีกเลี่ยงการสร้างAdsLoader
อินสแตนซ์ใหม่สำหรับคำขอแต่ละรายการ การสร้างอินสแตนซ์ใหม่
AdsLoader
ต้องใช้เวลาในการโหลดและใช้ทรัพยากรของอุปกรณ์เพิ่มเติม
ขอโฆษณาล่วงหน้าก่อนการเล่น
หากคุณมีสิทธิ์เข้าถึงอินสแตนซ์ AdsLoader
ก่อนเริ่มการเล่นโฆษณา
คุณก็เรียกใช้เมธอด
AdsLoader.requestAds()
ได้ล่วงหน้า การเรียกใช้ฟังก์ชันนี้จะเริ่มโหลดโฆษณาก่อนแสดงวิดีโอ เมื่อผู้ใช้พร้อมที่จะเริ่มเล่นเนื้อหา ให้เรียกใช้เมธอด
AdsManager.init()
และรอเหตุการณ์ LOADED
เพื่อเล่นโฆษณา
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-05 UTC
[null,null,["อัปเดตล่าสุด 2025-09-05 UTC"],[],[],null,["# Improve IMA load time\n\nThe IMA SDK loads dependencies to request ads, measure viewability and\nreport ad impressions. By initializing IMA before you make an ad request, you\nmaximize the time to load IMA dependencies before ad playback. This page covers\nhow to handling IMA load times in your app.\n\nCall `ImaSdkFactory.initialize()`\n---------------------------------\n\nThe\n[`ImaSdkFactory.initialize()`](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/ImaSdkFactory#initialize(android.content.Context,com.google.ads.interactivemedia.v3.api.ImaSdkSettings))\nmethod starts to preload SDK resources in advance of the first ad request. To\nuse `initialize()`, you need IMA version 3.35.1 or higher.\n\nCall `ImaSdkFactory.initialize()` on application startup, or as early in the\napplication's lifecycle as your app structure allows. The `initialize()` call\ntakes the following parameters:\n\n- **`context`**: Uses the application context, which is always available during the lifecycle of the application.\n- **`settings`** : Pass the an [`ImaSdkSettings`](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/ImaSdkSettings) object with its values set. The IMA settings used in the `initialize()` call must be the same as the settings values used in the `createAdsLoader()` call. The IMA SDK utilizes these settings, particularly the language setting, for cache key. We don't recommend using test or fake values for the settings used in the `initialize()` method call, as cache misses might occur and increase ad load time.\n\nReuse the `AdsLoader` instance\n------------------------------\n\nTo improve IMA load time, we recommend you reuse the same\n[`AdsLoader`](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/AdsLoader)\ninstance. The `AdsLoader` interface can handle multiple ad or stream requests.\nAvoid creating a new `AdsLoader` instance for each request. Creating a new\n`AdsLoader` instance requires a load time, and uses additional device resources.\n\nRequest ads in advance of playback\n----------------------------------\n\nIf you have access to the `AdsLoader` instance prior to starting ad playback,\nyou can also call the\n[`AdsLoader.requestAds()`](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/AdsLoader#requestAds(com.google.ads.interactivemedia.v3.api.AdsRequest))\nmethod early. Making this call starts loading pre-roll ads. When the user\nis ready to start content playback, call the\n[`AdsManager.init()`](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/BaseManager#init())\nmethod and wait for the `LOADED` event to play ads."]]