🔌Initialize SDK

To make all of the features of the Playtime Ads SDK available, you need to initialize it first. This initialization happens asynchronously in the background, with its completion indicated by a callback method. Make sure to initialize the SDK immediately after the app launches and after the user login in the app.

Best practices for the SDK initialization:

  • Initialize early: Initialize the SDK as soon as possible after your app starts. This ensures all SDK features are ready for use right away.

  • Initialize after your app authentication: Once a user signs up or logs in in your app, initialize the SDK again with the latest user details. This updates the userID within the SDK and ensures reward will be delivered to the user. If a user is not login in your app, you can pass blank or 0.

  • Initialization triggers: Call the init method at the app start and after login

Initialization

The initialization will run in the main application process asynchronously in the background and notify you when it is finished by invoking the OfferWallInitListener's onInitSuccess or onAlreadyInitializing or onInitFailed method

Important: Initialization must happen on the main thread since it's a UI-related action. Calling any of the init methods off the main thread could lead to app disruptions.

PlaytimeAds.getInstance().destroy(); // clears your previous session
PlaytimeAds.getInstance().init(context, applicationKey, userID, new OfferWallInitListener() {
     @Override public void onInitSuccess() {
      Log.e("TAG", "onInitSuccess");
      }
     @Override public void onAlreadyInitializing() {
      Log.e("TAG", "onAlreadyInitializing");
      }
     @Override public void onInitFailed(String error) {
      Log.e("TAG", "onInitFailed: " + error);
      }
  });

Parameters:

Re-initialize Playtime Ads SDK after user login. Otherwise rewarding the user is not guaranteed

Clear Session on Logout

Don't miss to clear Playtime Ads session when users logout from the app.

PlaytimeAds.getInstance().destroy(); // clears your previous session

Last updated