缩短了 IMA 加载时间
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
IMA SDK 会加载依赖项以请求广告、衡量可见度并报告广告展示次数。通过在发出广告请求之前初始化 IMA,您可以最大限度地延长在广告播放前加载 IMA 依赖项的时间。本页介绍了如何在应用中处理 IMA 加载时间。
拨打 ImaSdkFactory.initialize()
ImaSdkFactory.initialize()
方法会在发出首项广告请求之前开始预加载 SDK 资源。如需使用 initialize()
,您需要 IMA 3.35.1 或更高版本。
在应用启动时调用 ImaSdkFactory.initialize()
,或者在应用生命周期中尽早调用 ImaSdkFactory.initialize()
(前提是应用结构允许)。initialize()
调用采用以下参数:
context
:使用应用上下文,该上下文在应用生命周期内始终可用。
settings
:传递已设置值的 ImaSdkSettings
对象。initialize()
调用中使用的 IMA 设置必须与 createAdsLoader()
调用中使用的设置值相同。IMA SDK 会将这些设置(尤其是语言设置)用作缓存键。我们不建议为 initialize()
方法调用中使用的设置使用测试值或虚假值,因为可能会发生缓存未命中并增加广告加载时间。
重复使用 AdsLoader
实例
为了缩短 IMA 加载时间,我们建议您重复使用相同的 AdsLoader
实例。AdsLoader
接口可以处理多个广告或串流请求。避免为每个请求创建新的 AdsLoader
实例。创建新的 AdsLoader
实例需要加载时间,并且会使用额外的设备资源。
在播放前请求广告
如果您在开始播放广告之前有权访问 AdsLoader
实例,还可以提前调用 AdsLoader.requestAds()
方法。进行此调用会开始加载前贴片广告。当用户准备好开始播放内容时,调用 AdsManager.init()
方法并等待 LOADED
事件以播放广告。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):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."]]