rafaelsz
Contributor
Contributor

Android SDK init on main thread

Does anybody know how to initialize the client SDK on Android not on main thread? 

The issue is that 

SDKManager.init(context)

has to be called on main thread or it will throw:

java.lang.IllegalStateException: Method addObserver must be called on the main thread
at androidx.lifecycle.LifecycleRegistry.enforceMainThreadIfNeeded(LifecycleRegistry.java:317)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:172)
at com.airwatch.sdk.SDKManager.attachLaunchEventCallback(SDKManager.java:297)
at com.airwatch.sdk.SDKManager.initOperationalDataReporting(SDKManager.java:289)
at com.airwatch.sdk.SDKManager.<init>(SDKManager.java:258)
at com.airwatch.sdk.SDKManager.getInstance(SDKManager.java:552)
at com.airwatch.sdk.SDKManager.init(SDKManager.java:277)

and this method call has a 30 second timeout that blocks the main thread when there is an issue connecting the the airwatch agent service.

The docs show a call to init from a thread but clearly this does not work because of the above error:

private void startSDK() { new Thread(new Runnable() {
@Override
public void run() {
try {
final SDKManager initSDKManager = SDKManager.init(MainActivity.this);
sdkManager = initSDKManager;
toastHere(
"Workspace ONE console version:" + initSDKManager.getConsoleVersion());
}
catch (Exception exception) {
sdkManager = null;
toastHere(
} }
}).start(); }

 

Labels (1)
0 Kudos
0 Replies