ปรับปรุงเวลาในการโหลด IMA
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
IMA SDK จะโหลดทรัพยากรที่เกี่ยวข้องเพื่อขอโฆษณา วัดการมองเห็นโฆษณา และรายงานการแสดงโฆษณา การกำหนดค่า IMA ก่อนส่งคำขอโฆษณาจะช่วยให้คุณมีเวลาในการโหลดทรัพยากร IMA ที่จำเป็นก่อนเล่นโฆษณาได้สูงสุด หน้านี้จะอธิบายวิธีจัดการเวลาในการโหลด IMA ในแอป
โทร ImaSdkFactory.initialize()
วิธีการ ImaSdkFactory.initialize()
จะเริ่มต้นโหลดทรัพยากร SDK ล่วงหน้าก่อนการขอโฆษณาครั้งแรก หากต้องการใช้ initialize()
คุณต้องมี IMA เวอร์ชัน 3.35.1 ขึ้นไป
เรียก ImaSdkFactory.initialize()
เมื่อแอปพลิเคชันเริ่มต้น หรือเรียกให้เร็วที่สุดเท่าที่โครงสร้างแอปอนุญาตในวงจรของแอปพลิเคชัน การเรียก initialize()
ใช้พารามิเตอร์ต่อไปนี้
context
: ใช้บริบทแอปพลิเคชัน ซึ่งพร้อมใช้งานเสมอตลอดอายุการใช้งานของแอปพลิเคชัน
settings
: ส่งออบเจ็กต์ ImaSdkSettings
ที่มีการตั้งค่าค่า การตั้งค่า IMA ที่ใช้ในการเรียก initialize()
ต้องเหมือนกับค่าการตั้งค่าที่ใช้ในการเรียก createAdsLoader()
IMA SDK จะใช้การตั้งค่าเหล่านี้ โดยเฉพาะการตั้งค่าภาษา สำหรับคีย์แคช เราไม่แนะนําให้ใช้ค่าทดสอบหรือค่าสมมติสําหรับการตั้งค่าที่ใช้ในinitialize()
method call เนื่องจากอาจเกิดแคชไม่พบและทำให้เวลาในการโหลดโฆษณาเพิ่มขึ้น
ใช้อินสแตนซ์ AdsLoader
ซ้ำ
เราขอแนะนำให้คุณนําAdsLoader
เดิมมาใช้ซ้ำเพื่อปรับปรุงเวลาในการโหลด IMA อินเทอร์เฟซ AdsLoader
สามารถจัดการคําขอโฆษณาหรือสตรีมหลายรายการ
หลีกเลี่ยงการสร้างอินสแตนซ์ AdsLoader
ใหม่สำหรับคำขอแต่ละรายการ การสร้างAdsLoader
อินสแตนซ์ใหม่ต้องใช้เวลาในการโหลดและใช้ทรัพยากรของอุปกรณ์เพิ่มเติม
ขอโฆษณาล่วงหน้าก่อนเล่น
หากมีสิทธิ์เข้าถึงอินสแตนซ์ AdsLoader
ก่อนเริ่มเล่นโฆษณา คุณก็เรียกใช้เมธอด AdsLoader.requestAds()
ได้ตั้งแต่เนิ่นๆ การเรียกใช้นี้จะเริ่มต้นการโหลดโฆษณาก่อนแสดงวิดีโอ เมื่อผู้ใช้พร้อมที่จะเริ่มเล่นเนื้อหา ให้เรียกใช้เมธอด AdsManager.init()
แล้วรอเหตุการณ์ LOADED
เพื่อเล่นโฆษณา
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 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."]]