Playtime SDK
  • Overview
    • 💡Introduction
    • ✨Our Features
  • Getting Started
    • 🖥️Create Publisher Account
    • 📲Create Your App
  • ANDROID SDK INTEGRATION
    • 📥Add Dependency
    • 🔌Initialize SDK
    • 💸Launch Offerwall
  • PAYOUT
    • 🛡️Setup S2S Postback
  • OTHER
    • 📑FAQs
    • ✒️Terms of Service
  • 🏷️Sample App - Java
Powered by GitBook
On this page
  • Best practices for the SDK initialization:
  • Initialization
  • Parameters:
  • Clear Session on Logout
  1. ANDROID SDK INTEGRATION

Initialize SDK

To make all of the features of the Playtime 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().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);
      }
  });
PlaytimeAds.getInstance().destroy()// clears your previous session
PlaytimeAds.getInstance().init(context, applicationKey, userID,object : OfferWallInitListener {
      override fun onInitSuccess() {
      Log.e("TAG", "onInitSuccess");
      }
      override fun onAlreadyInitializing() {
      Log.e("TAG", "onAlreadyInitializing");
      }
      override fun onInitFailed(error: String?) {
      Log.e("TAG", "onInitFailed: " + error);
      }
  })

Parameters:

Parameter
Type
Explanation

UserID

String

A custom that will be used to identify your user uniquely. This will be sent back in the postback. If user is not logged-in in your app, please pass 0 or blank in UserId. Max character limit is 50 characters.

applicationKey

String

Application key provided in publisher panel for your application

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

Note: If SDK is already initialized, You need to destroy previous session first in order to initialize it again for new UserId.

Clear Session on Logout

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

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

Last updated 2 months ago

🔌