改善 IMA 載入時間
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
IMA SDK 會載入依附元件,以便請求廣告、評估可視度及回報廣告曝光次數。在提出廣告請求前初始化 IMA,可盡量爭取時間載入 IMA 依附元件,再播放廣告。本頁說明如何在應用程式中處理 IMA 載入時間。
撥打 ImaSdkFactory.initialize()
ImaSdkFactory.initialize()
方法會在發出第一個廣告請求前,開始預先載入 SDK 資源。如要使用 initialize()
,請務必使用 IMA 3.35.1 以上版本。
在應用程式啟動時呼叫 ImaSdkFactory.initialize()
,或盡早在應用程式生命週期中呼叫,具體時間取決於應用程式結構。initialize()
呼叫會採用下列參數:
context
:使用應用程式內容,這在應用程式生命週期中一律可用。
settings
:傳遞已設定值的 ImaSdkSettings
物件。initialize()
呼叫中使用的 IMA 設定,必須與 createAdsLoader()
呼叫中使用的設定值相同。IMA SDK 會使用這些設定 (尤其是語言設定) 做為快取鍵。我們不建議在 initialize()
方法呼叫中使用的設定採用測試或虛假值,因為這樣可能會發生快取未命中,並增加廣告載入時間。
重複使用 AdsLoader
執行個體
為縮短 IMA 載入時間,建議您重複使用相同的 AdsLoader
執行個體。AdsLoader
介面可處理多個廣告或串流要求。
請避免為每個要求建立新的 AdsLoader
例項。建立新的AdsLoader
執行個體需要載入時間,且會使用額外的裝置資源。
在播放前要求廣告
如果您在開始播放廣告前存取 AdsLoader
執行個體,也可以提早呼叫 AdsLoader.requestAds()
方法。進行這項呼叫後,系統就會開始載入片頭廣告。使用者準備好開始播放內容時,請呼叫 AdsManager.init()
方法,並等待 LOADED
事件播放廣告。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-05 (世界標準時間)。
[null,null,["上次更新時間:2025-09-05 (世界標準時間)。"],[],[],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."]]