Initializing the SDK Asynchronously
InitAsync
Initializing the SDK
1
|
HWMSdk.initAsync(Application,OpenSDKConfig, SdkCallback) |
API Description
This API is used to asynchronously initialize the SDK and prepare the environment. Before calling other APIs, complete asynchronous initialization and receive the onSuccess callback. Call this API only once. Before calling this API, register a listener of the activity lifecycle in onCreate of Application, so that the SDK can obtain the current activity and jump to a specified page by listening to the activity lifecycle.
Precautions
1. If you have requirements on the initialization speed, use the asynchronous initialization API.
2. Complete initialization before using other SDK functions.
3. Before calling the asynchronous initialization API, register an activity lifecycle listener in onCreate of Application by referring to the sample code.
Method Definition
1 2 3 4 5 6 7 8 |
/** * SDK asynchronous initialization API. Complete initialization before using any other functions of the UISDK. * * @param application Indicates the input application, which is internally converted to applicationContext for users to obtain system resources. * @param sdkConfig Indicates the SDK configuration. * @param sdkCallback Indicates the SDK callback. */ void initAsync(@NonNull Application application, OpenSDKConfig sdkConfig, SdkCallback<Integer> sdkCallback) |
Parameter Description
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
application |
Yes |
Application |
Application object. |
sdkConfig |
Yes |
OpenSDKConfig |
SDK configuration object. |
SdkCallback |
Yes |
SdkCallback<Integer> |
Callback of the asynchronous initialization result. |
Sample Code
// [Important] Register a listener of the activity lifecycle in onCreate of Application. registerActivityLifecycleCallbacks(new ActivityLifecycleHandle()); // Demonstrate the initialization of subthreads. new Thread(() -> HWMSdk.initAsync(mApp, sdkConfig, new SdkCallback<Integer>() { @Override public void onFailed(SDKERR sdkerr) { HCLog.e(TAG, "init failed:" + sdkerr.getDescription()); } @Override public void onSuccess(Integer integer) { HCLog.i(TAG, "init success:" + integer); // Implement other SDK-related logic. mHandler.sendEmptyMessage(0); } })).start();
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot