Initialize the SDK

You must initialize the adjoe SDK before you can use any of its features. To do this, call Adjoe.init(Context, String, Adjoe.Options, AdjoeInitializationListener).

The initialization will run in the main application process asynchronously in the background and notify you when it is finished by invoking the AdjoeInitializationListener's onInitialisationFinished or onInitialisationError method.

After one successful initialization all following calls to Adjoe.init will immediately invoke onInitialisationFinished until your app is removed from the heap.

Best practices for the SDK initialization:

  • Initialize early: You should initialize the SDK as soon as possible after your app starts to make sure that all adjoe features are available when you want to use them.

  • Initialize regularly: For the best user experience, we highly recommend to call this method every time your app comes to the foreground. This should not be noticeable in your app's performance.

  • Initialization triggers: Good places to call this method are the app start and your MainActivity's onResume method.

Example

public class MainActivity extends Activity {

    @Override
    protected void onResume() {
        super.onResume();
        Adjoe.init(this, "sdkHash", options, new AdjoeInitialisationListener() {

            @Override
            public void onInitialisationFinished() {
                // the adjoe SDK was initialized successfully
            }

            @Override
            public void onInitialisationError(Exception exception) {
                // an error occurred while initializing the adjoe SDK.
                // note that exception might be null
            }
        });
    }
}

The parameters to this call are as follows:

  • Context context: Your application's context.

  • String sdkHash: Your adjoe SDK hash.

  • Adjoe.Options options: An object to pass additional options to the adjoe SDK when initializing. This parameter is optional and you can call Adjoe.init(Context, String) or Adjoe.init(Context, String, AdjoeInitializationListener) instead.

  • AdjoeInitializationListener listener: A listener which informs you about whether the adjoe SDK was initialized successfully or not. This parameter is optional and you can call Adjoe.init(Context, String) or Adjoe.init(Context, String, Adjoe.Options) instead.

You can create an Adjoe.Options object in the following way:

Adjoe.Options options = new Adjoe.Options()
    .setUserId(userId)
    .setApplicationProcessName(processName)
    .setAdjoeParams(adjoeParams);
  • String userId: A custom identifier that you wish to assign to this user. If you don't have an identifier for your user already, the adjoe SDK will generate one. You can then access it by calling Adjoe.getUserId(Context).

  • String applicationProcessName: A custom identifier that you will need to set if you manually set/change the android.process for application tag in androidManifest file.

  • Object AdjoeParams: A holder of User Acquisition parameters and Playtime placement.

If you want to use S2S payout, you have to set the user id in order to match the payout to your user.

Adjoe Parameters

You can pass additional UA and placement parameters when you initialize the SDK. Call

AdjoeParams adjoeParams = new AdjoeParams.Builder()
                .setUaNetwork("network")
                .setUaChannel("channel")
                .setUaSubPublisherCleartext("SubPublisherCleartext")
                .setUaSubPublisherEncrypted("SubPublisherEncrypted")
                .setPlacement("placement")
                .build();
Adjoe.Options options = new Adjoe.Options()
    .setAdjoeParams(adjoeParams);
Adjoe.init(context, "<your_sdk_hash>", options, listener);

The isInitialized method

To check whether the SDK is initialized you can call Adjoe.isInitialized(). This will return true if the SDK is initialized and false otherwise. However, you should not condition calling init on the result of isInitialized because the SDK will do some checks on its own. You should not do something like the following as it can lead to bad user experience:

@Override
protected void onResume() {
    super.onResume();
    if (!Adjoe.isInitialized()) {
        Adjoe.init(context, sdkHash, options, listener);
    }
}

Instead, just call init without checking for isInitialized. You can however use isInitialized e.g. for debugging or to check whether the SDK is initialized before calling other methods of the SDK like requestRewards.

Last updated