Stay organized with collections
Save and categorize content based on your preferences.
Most uses of the IMA SDK only require managing a single ad request at a time. However some edge case implementations, such as preloading ad data before the user selects a video, may require making multiple concurrent requests. Since ad requests are made asynchronously, ensuring the proper ad manager is associated with the correct context can seem to be a daunting task.
To simplify the process of differentiating multiple ad managers, the IMA SDK for Android allows publishers to pass in any value or object to the UserRequestContext field of any ad request. This value or object can then be retrieved in the AdsManagerLoadedEvent handler, by using the method getUserRequestContext().
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["\u003cp\u003eThe IMA SDK for Android allows for managing multiple, concurrent ad requests by associating a unique context with each request.\u003c/p\u003e\n"],["\u003cp\u003ePublishers can use the \u003ccode\u003eUserRequestContext\u003c/code\u003e field of an ad request to pass in a custom identifier (e.g., a Map).\u003c/p\u003e\n"],["\u003cp\u003eThis identifier can then be retrieved in the \u003ccode\u003eAdsManagerLoadedEvent\u003c/code\u003e or \u003ccode\u003eAdErrorEvent\u003c/code\u003e handlers using \u003ccode\u003egetUserRequestContext()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThis functionality simplifies the process of differentiating between ad managers tied to specific video content or elements.\u003c/p\u003e\n"]]],[],null,["# Handle multiple ad requests\n\nMost uses of the IMA SDK only require managing a single ad request at a time. However some edge case implementations, such as preloading ad data before the user selects a video, may require making multiple concurrent requests. Since ad requests are made asynchronously, ensuring the proper ad manager is associated with the correct context can seem to be a daunting task.\n\nTo simplify the process of differentiating multiple ad managers, the IMA SDK for Android allows publishers to pass in any value or object to the [UserRequestContext](https://developers.google.com/interactive-media-ads/docs/sdks/android/dai/api/reference/com/google/ads/interactivemedia/v3/api/AdsRequest.html#public-abstract-void-setuserrequestcontext-object-userrequestcontext) field of any ad request. This value or object can then be retrieved in the [AdsManagerLoadedEvent](https://developers.google.com/interactive-media-ads/docs/sdks/android/dai/api/reference/com/google/ads/interactivemedia/v3/api/AdsManagerLoadedEvent) handler, by using the method [getUserRequestContext()](https://developers.google.com/interactive-media-ads/docs/sdks/android/dai/api/reference/com/google/ads/interactivemedia/v3/api/AdsManagerLoadedEvent.html#public-abstract-object-getuserrequestcontext).\n\nExample\n-------\n\n ...\n\n adsLoader = sdkFactory.createAdsLoader(context, imaSdkSettings, adDisplayContainer);\n\n Map\u003cString, String\u003e userContextA = new HashMap\u003cString, String\u003e();\n Map\u003cString, String\u003e userContextB = new HashMap\u003cString, String\u003e();\n userContextA.put(\"id\", \"Request A\");\n userContextB.put(\"id\", \"Request B\");\n userContextA.put(\"element\", \"videoElementA\");\n userContextB.put(\"element\", \"videoElementB\");\n adRequestA.setUserRequestContext(userContextA);\n adRequestB.setUserRequestContext(userContextB);\n\n adsLoader.addAdsLoadedListener(\n new AdsLoader.AdsLoadedListener() {\n @Override\n public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) {\n Map\u003cString, String\u003e context = adsManagerLoadedEvent.getUserRequestContext();\n adsManager = adsManagerLoadedEvent.getAdsManager();\n Log.i(\"ImaExample\", \"Successfully loaded ID: \" + context.get(\"id\"));\n }\n });\n\n adsLoader.addAdErrorListener(\n new AdErrorEvent.AdErrorListener() {\n @Override\n public void onAdError(AdErrorEvent adErrorEvent) {\n Map\u003cString, String\u003e context = adErrorEvent.getUserRequestContext();\n Log.i(\"ImaExample\", \"Error with AdRequest. ID: \" + context.get(\"id\"));\n Log.i(\"ImaExample\", \"Ad Error: \" + adErrorEvent.getError().getMessage());\n }\n });\n\n adsLoader.requestAds(adRequestA);\n adsLoader.requestAds(adRequestB);\n\n ..."]]