MoPub SDK Initialization

Starting with MoPub SDK v. 5.0.0, after you have integrated the MoPub SDK and created an ad unit, you must call the MoPub API for initialization (MoPub.initializeSdk()) before you send any ad requests.

You only need to call the MoPub.initializeSdk() once per app’s lifecycle, typically when the app is launched, using any valid ad unit. Initialization is required for several functions, including:

  • GDPR consent mechanisms
  • Rewarded video pre-initialization

If you have been using MoPubRewardedVideos.initializeRewardedVideo(), its function is now included in the new initialization, so make sure to remove all the MoPubRewardedVideos.initializeRewardedVideo() calls from your code.

Initialization Instructions

To initialize the MoPub SDK:

  1. In your Activity’s onCreate() (or equivalent), instantiate an SdkConfiguration via a Builder with any valid ad unit ID from your app, optionally your mediation settings, and a list of mediated rewarded video adapters (also optional).
  2. Call MoPub.initializeSdk() and pass in a Context (we recommend the Activity type), the SdkConfiguration object, and an SdkInitializationListener object.

Example

// A list of rewarded video adapters to initialize
List<String> networksToInit = new ArrayList<String>();
networksToInit.add("com.mopub.mobileads.VungleRewardedVideo");

SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder("AD_UNIT_ID")
                                                        .withMediationSettings("MEDIATION_SETTINGS")
                                                        .withNetworksToInit(networksToInit)
                                                        .build();

MoPub.initializeSdk(this, sdkConfiguration, initSdkListener());

private SdkInitializationListener initSdkListener() {
   return new SdkInitializationListener() {
       @Override
       public void onInitializationFinished() {
           /* MoPub SDK initialized. 
           Check if you should show the consent dialog here, and make your ad requests. */
       }
   };
}

Last updated December 05, 2018

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2018 MoPub Inc.