Skip to content

New SDK Initialization API

AppLovin Android SDK 12.4.0 introduces a new set of SDK initialization APIs. These deprecate the old way of initializing the SDK. The new APIs provide a straightforward and organized way to initialize the SDK, while addressing issues with the old APIs.

You can find your SDK key in the Account > General > Keys section of the AppLovin dashboard.

Create the SDK Initialization Configuration

Before you initialize the SDK, create an initialization configuration object for the SDK. This object allows you to configure the properties that the SDK will initialize with. These initialization properties are immutable, with the exception of AppLovinSdkSettings which contains mutable properties that can be changed during the lifetime of the app.

// Create the initialization configuration
AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( "«SDK-key»", this )
.setMediationProvider( AppLovinMediationProvider.MAX )
// Perform any additional configuration/setting changes
.build();

Initialize the SDK

Initialize the AppLovin SDK with the initialization configuration object as early as possible (for example, in the onCreate() of the launch activity or Application class). This maximizes how much time the SDK has to cache mediated networks ads, which results in a better user experience.

public class MainActivity extends Activity
{
protected void onCreate(Bundle savedInstanceState)
{
// Create the initialization configuration
AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( "«SDK-key»", this )
.setMediationProvider( AppLovinMediationProvider.MAX )
.build();
// Initialize the SDK with the configuration
AppLovinSdk.getInstance( this ).initialize( initConfig, new AppLovinSdk.SdkInitializationListener()
{
@Override
public void onSdkInitialized(final AppLovinSdkConfiguration sdkConfig)
{
// Start loading ads
}
} );
}
}

Example

Below is a sample integration that calls the new APIs.

// Create the initialization configuration
AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( "«SDK-key»", this )
.setMediationProvider( AppLovinMediationProvider.MAX )
.setSegmentCollection( MaxSegmentCollection.builder()
.addSegment( new MaxSegment( 849, Arrays.asList( 1, 3 ) ) )
.build() )
.build();
// Configure the SDK settings if needed before or after SDK initialization.
val settings = AppLovinSdk.getInstance( this ).getSettings();
settings.setUserIdentifier( "«user-ID»" );
settings.setExtraParameter( "uid2_token", "«token-value»" );
settings.getTermsAndPrivacyPolicyFlowSettings().setEnabled( true );
settings.getTermsAndPrivacyPolicyFlowSettings().setPrivacyPolicyUri( Uri.parse( "«https://your_company_name.com/privacy_policy»" ) );
settings.getTermsAndPrivacyPolicyFlowSettings().setTermsOfServiceUri( Uri.parse( "«https://your_company_name.com/terms_of_service»" ) );
// Initialize the SDK with the configuration
AppLovinSdk.getInstance( this ).initialize( initConfig, new AppLovinSdk.SdkInitializationListener()
{
@Override
public void onSdkInitialized(final AppLovinSdkConfiguration sdkConfig)
{
// Start loading ads
}
} );