Cải thiện thời gian tải IMA
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
SDK IMA tải các phần phụ thuộc để yêu cầu quảng cáo, đo lường khả năng xem và báo cáo lượt hiển thị quảng cáo. Bằng cách khởi chạy IMA trước khi tạo yêu cầu quảng cáo, bạn sẽ tối đa hoá thời gian tải các phần phụ thuộc IMA trước khi phát quảng cáo. Trang này trình bày cách xử lý thời gian tải IMA trong ứng dụng.
Gọi cho ImaSdkFactory.initialize()
Phương thức ImaSdkFactory.initialize()
bắt đầu tải trước các tài nguyên SDK trước yêu cầu quảng cáo đầu tiên. Để sử dụng initialize()
, bạn cần có IMA phiên bản 3.35.1 trở lên.
Gọi ImaSdkFactory.initialize()
khi khởi động ứng dụng hoặc càng sớm càng tốt trong vòng đời của ứng dụng khi cấu trúc ứng dụng cho phép. Lệnh gọi initialize()
có các tham số sau:
context
: Sử dụng ngữ cảnh ứng dụng, luôn có sẵn trong vòng đời của ứng dụng.
settings
: Truyền đối tượng ImaSdkSettings
đã đặt giá trị. Chế độ cài đặt IMA dùng trong lệnh gọi initialize()
phải giống với giá trị cài đặt dùng trong lệnh gọi createAdsLoader()
. SDK IMA sử dụng các chế độ cài đặt này, đặc biệt là chế độ cài đặt ngôn ngữ, cho khoá bộ nhớ đệm. Bạn không nên sử dụng giá trị thử nghiệm hoặc giá trị giả cho các chế độ cài đặt được sử dụng trong lệnh gọi phương thức initialize()
, vì bộ nhớ đệm có thể bị thiếu và làm tăng thời gian tải quảng cáo.
Sử dụng lại thực thể AdsLoader
Để cải thiện thời gian tải IMA, bạn nên sử dụng lại cùng một thực thể AdsLoader
. Giao diện AdsLoader
có thể xử lý nhiều yêu cầu quảng cáo hoặc yêu cầu phát trực tuyến.
Tránh tạo một thực thể AdsLoader
mới cho mỗi yêu cầu. Việc tạo một thực thể AdsLoader
mới sẽ mất thời gian tải và sử dụng thêm tài nguyên thiết bị.
Yêu cầu quảng cáo trước khi phát
Nếu có quyền truy cập vào thực thể AdsLoader
trước khi bắt đầu phát quảng cáo, bạn cũng có thể gọi sớm phương thức AdsLoader.requestAds()
. Việc thực hiện lệnh gọi này sẽ bắt đầu tải quảng cáo trước video. Khi người dùng sẵn sàng bắt đầu phát nội dung, hãy gọi phương thức AdsManager.init()
và chờ sự kiện LOADED
phát quảng cáo.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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."]]