From fe89bd0a2a53e6c2a2aa0f5c31d6a94496af4606 Mon Sep 17 00:00:00 2001 From: Arief Nur Putranto Date: Fri, 20 Dec 2024 13:34:16 +0700 Subject: [PATCH] prevent crash when destroy in file qiscusNetworkChecker --- README.md | 2 +- .../QiscusNetworkCheckerJobService.java | 26 ++++++++++++++----- docs/index.md | 2 +- gradle.properties | 4 +-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f41cff6b..b29cdc5e 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Second, you need to add SDK dependencies inside your app .gradle. Then, you need ``` dependencies { ... - implementation 'com.qiscus.sdk:chat-core:1.8.4' + implementation 'com.qiscus.sdk:chat-core:1.8.5' } ``` diff --git a/chat-core/src/main/java/com/qiscus/sdk/chat/core/service/QiscusNetworkCheckerJobService.java b/chat-core/src/main/java/com/qiscus/sdk/chat/core/service/QiscusNetworkCheckerJobService.java index c504b94a..c05a52bf 100644 --- a/chat-core/src/main/java/com/qiscus/sdk/chat/core/service/QiscusNetworkCheckerJobService.java +++ b/chat-core/src/main/java/com/qiscus/sdk/chat/core/service/QiscusNetworkCheckerJobService.java @@ -38,6 +38,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; +import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; @@ -116,18 +117,21 @@ public void onCreate() { @Override public void onDestroy() { - QiscusAndroidUtil.runOnBackgroundThread(() -> { + + Executors.newSingleThreadExecutor().execute(() -> { try { unregisterReceiver(networkStateReceiver); QiscusLogger.print(TAG, "onDestroy"); EventBus.getDefault().unregister(this); }catch (IllegalArgumentException e) { // already unregistered + }catch (RuntimeException r) { + QiscusErrorLogger.print(r); + } catch (Exception e) { + QiscusErrorLogger.print(e); } - }); - super.onDestroy(); } @@ -151,10 +155,18 @@ public void onUserEvent(QiscusUserEvent userEvent) { } private void stopJob() { - QiscusLogger.print(TAG, "stopJob"); - JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); - if (jobScheduler != null) { - jobScheduler.cancel(STATIC_JOB_ID); + try { + QiscusLogger.print(TAG, "stopJob"); + JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); + if (jobScheduler != null) { + jobScheduler.cancel(STATIC_JOB_ID); + } + }catch (IllegalArgumentException e) { + // already unregistered + }catch (RuntimeException r) { + QiscusErrorLogger.print(r); + } catch (Exception e) { + QiscusErrorLogger.print(e); } } } diff --git a/docs/index.md b/docs/index.md index e7464935..27fe12d7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -80,7 +80,7 @@ Secondly, you need to add SDK dependencies inside your app .gradle. Then, you ne ``` dependencies { ... - implementation 'com.qiscus.sdk:chat-core:1.8.4' + implementation 'com.qiscus.sdk:chat-core:1.8.5' } ``` diff --git a/gradle.properties b/gradle.properties index c92e4a9b..841faf48 100644 --- a/gradle.properties +++ b/gradle.properties @@ -43,7 +43,7 @@ chatVersionPatch=0 # === qiscus chat-core library version === chatCoreVersionMajor=1 chatCoreVersionMinor=8 -chatCoreVersionPatch=4 +chatCoreVersionPatch=5 # === qiscus default base url BASE_URL_SERVER="https://api.qiscus.com/" @@ -59,7 +59,7 @@ android.useAndroidX=true libraryGroupId=com.qiscus.sdk libraryArtifactId=chat-core -libraryVersion=1.8.4 +libraryVersion=1.8.5 libraryGroupIdChat=com.qiscus.sdk libraryArtifactIdChat=chat