Skip to content

Commit

Permalink
prevent crash when destroy in file qiscusNetworkChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
Arief Nur Putranto committed Dec 20, 2024
1 parent 7308171 commit fe89bd0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand All @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -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
Expand Down

0 comments on commit fe89bd0

Please sign in to comment.