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 luồng Chèn quảng cáo động (DAI), đ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 phát trực tuyến, 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 trực tuyến. 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 truyền trực tuyến đầ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 truyền trực tuyến 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 trực tuyến, bạn cũng có thể gọi sớm phương thức AdsLoader.requestStream()
. Thao tác gọi này sẽ bắt đầu tải luồng DAI. Khi người dùng sẵn sàng bắt đầu phát trực tuyến, hãy gọi phương thức StreamManager.init()
để khởi chạy quá trình phát trực tuyến.
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-21 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-21 UTC."],[],[],null,["# Improve IMA load time\n\nThe IMA SDK loads dependencies to request Dynamic Ad Insertion (DAI) streams,\nmeasure viewability and report ad impressions. By initializing IMA before you\nmake a stream request, you maximize the time to load IMA dependencies before\nstream playback. This page covers how to handling IMA load times in your app.\n\nCall `ImaSdkFactory.initialize()`\n---------------------------------\n\nThe\n[`ImaSdkFactory.initialize()`](/ad-manager/dynamic-ad-insertion/sdk/android/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 stream request.\nTo use `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`](/ad-manager/dynamic-ad-insertion/sdk/android/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 streams in advance of playback\n--------------------------------------\n\nIf you have access to the `AdsLoader` instance prior to starting stream\nplayback, you can also call the\n[`AdsLoader.requestStream()`](/ad-manager/dynamic-ad-insertion/sdk/android/api/reference/com/google/ads/interactivemedia/v3/api/AdsLoader#requestStream(com.google.ads.interactivemedia.v3.api.StreamRequest))\nmethod early. Making this call starts loading the DAI stream. When the user\nis ready to start stream playback, call the\n[`StreamManager.init()`](/ad-manager/dynamic-ad-insertion/sdk/android/api/reference/com/google/ads/interactivemedia/v3/api/BaseManager#init())\nmethod to initialize stream playback."]]