From ad0f458f1684f6baada1fd5afffae9a60eb87bc5 Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Mon, 1 Apr 2024 15:53:49 +0800 Subject: [PATCH] fix: initial Android SDK exception in other thread issue --- .../ClickstreamReactNativeModule.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/software/aws/solution/clickstreamreactnative/ClickstreamReactNativeModule.kt b/android/src/main/java/software/aws/solution/clickstreamreactnative/ClickstreamReactNativeModule.kt index 3699814..f1bf3ba 100644 --- a/android/src/main/java/software/aws/solution/clickstreamreactnative/ClickstreamReactNativeModule.kt +++ b/android/src/main/java/software/aws/solution/clickstreamreactnative/ClickstreamReactNativeModule.kt @@ -82,12 +82,18 @@ class ClickstreamReactNativeModule(reactContext: ReactApplicationContext) : val latch = CountDownLatch(1); try { reactApplicationContext.runOnUiQueueThread { - ClickstreamAnalytics.init(context, configuration) - latch.countDown() + try { + ClickstreamAnalytics.init(context, configuration) + promise.resolve(true) + isInitialized = true + } catch (exception: Exception) { + promise.resolve(false) + log.error("Clickstream SDK initialization failed with error: " + exception.message) + } finally { + latch.countDown() + } } latch.await() - promise.resolve(true) - isInitialized = true } catch (exception: Exception) { promise.resolve(false) log.error("Clickstream SDK initialization failed with error: " + exception.message)