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

Java
Kotlin
1
public class MainActivity extends Activity {
2
3
@Override
4
protected void onResume() {
5
super.onResume();
6
Adjoe.init(this, "sdkHash", options, new AdjoeInitialisationListener() {
7
8
@Override
9
public void onInitialisationFinished() {
10
// the adjoe SDK was initialized successfully
11
}
12
13
@Override
14
public void onInitialisationError(Exception exception) {
15
// an error occurred while initializing the adjoe SDK.
16
// note that exception might be null
17
}
18
});
19
}
20
}
Copied!
1
class MainActivity : AppCompatActivity {
2
3
override fun onCreate(savedInstanceState: Bundle?) {
4
Adjoe.init(this, "sdkHash", options, object: AdjoeInitialisationListener {
5
6
override fun onInitialisationFinished() {
7
// the adjoe SDK was initialized successfully
8
}
9
10
override fun onInitialisationError(exception: Exception?) {
11
// an error occurred while initializing the adjoe SDK.
12
// note that exception might be null
13
}
14
})
15
}
16
}
Copied!
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:
Java
Kotlin
1
Adjoe.Options options = new Adjoe.Options()
2
.setUserId(userId)
3
.setApplicationProcessName(processName)
4
.setAdjoeParams(adjoeParams);
Copied!
1
val options = Adjoe.Options()
2
.setUserId(userId)
Copied!
    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 offerwall 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
Java
Kotlin
1
AdjoeParams adjoeParams = new AdjoeParams.Builder()
2
.setUaNetwork("network")
3
.setUaChannel("channel")
4
.setUaSubPublisherCleartext("SubPublisherCleartext")
5
.setUaSubPublisherEncrypted("SubPublisherEncrypted")
6
.setPlacement("placement")
7
.build();
8
Adjoe.Options options = new Adjoe.Options()
9
.setAdjoeParams(adjoeParams);
10
Adjoe.init(context, "<your_sdk_hash>", options, listener);
Copied!
1
val adjoeParams = AdjoeParams.Builder()
2
.setUaNetwork("network")
3
.setUaChannel("channel")
4
.setUaSubPublisherCleartext("SubPublisherCleartext")
5
.setUaSubPublisherEncrypted("SubPublisherEncrypted")
6
.setPlacement("placement")
7
.build()
8
val options = Adjoe.Options()
9
.setAdjoeParams(adjoeParams)
10
Adjoe.init(context, "<your_sdk_hash>", options, listener)
Copied!

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:
Java
Kotlin
1
@Override
2
protected void onResume() {
3
super.onResume();
4
if (!Adjoe.isInitialized()) {
5
Adjoe.init(context, sdkHash, options, listener);
6
}
7
}
Copied!
1
protected fun onResume() {
2
super.onResume()
3
if (!Adjoe.isInitialized()) {
4
Adjoe.init(context, sdkHash, options, listener)
5
}
6
}
Copied!
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 modified 7mo ago
Copy link
Contents
Example