改善 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-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[],[],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."]]