GetSocial Android SDK Manual Initialization Guide

Disable Auto Initialization

By default GetSocial SDK is initialized automatically on application start. You can disable this behaviour and initialize from code.

If you’re using GetSocial Gradle plugin, set autoInit flag to false in your build.gradle file:

1
2
3
4
5
6
apply plugin: 'im.getsocial'

getsocial {
    appId "LK8A9cA0o07"
    autoInit false
}

If you’re not using Gradle plugin, add <meta-data> to your <application> tag in AndroidManifest.xml:

1
2
3
4
5
<application android:label="@string/app_name" ...>
    ...
    <meta-data android:name="im.getsocial.sdk.AutoInitSdk" android:value="false"/>
    ...
</application>

Initialize From Code

To initialize GetSocial SDK from code, just call GetSocial.init().

Most part of GetSocial APIs require initialised SDK. You can check SDK initialization state in sync or async way.

1
2
3
if (GetSocial.isInitialized()) {
    // use GetSocial
}

If you want to be notified about initialization complete, you can set an action, that will be invoked when SDK gets initialized or invoked immediately if it is already initialized:

1
2
3
4
5
6
GetSocial.whenInitialized(new Runnable() {
    @Override
    public void run() {
        // GetSocial is ready to be used
    }
});

It can be useful when you want to use GetSocial on application start, but you can not be sure is it ready for using, for example you want to retrieve referral data on application start:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
public class MainActivity extends Activity {
    ...
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...
        GetSocial.whenInitialized(new Runnable() {
            @Override
            public void run() {
                GetSocial.getReferralData(...);
            }
        });
        GetSocial.init();
        ...
    } 
    ...
}

Initialize With Dynamic Application Id

Also, you can specify application ID to initialize with from code:

1
2
String appId = ...;
GetSocial.init(appId);

Give us your feedback! Was this article helpful?

😀 🙁