From 058393d5438a621744568b4cf6a79835a2e713b0 Mon Sep 17 00:00:00 2001 From: Luke Date: Wed, 29 Jan 2020 03:14:13 -0500 Subject: [PATCH] Manually clean up DexterInstance when previous DexterActivity is finishing up: (#248) --- .../java/com/karumi/dexter/DexterInstance.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/dexter/src/main/java/com/karumi/dexter/DexterInstance.java b/dexter/src/main/java/com/karumi/dexter/DexterInstance.java index 4e834016..e3c62cee 100644 --- a/dexter/src/main/java/com/karumi/dexter/DexterInstance.java +++ b/dexter/src/main/java/com/karumi/dexter/DexterInstance.java @@ -124,11 +124,13 @@ void onActivityReady(Activity activity) { * Method called whenever the inner activity has been destroyed. */ void onActivityDestroyed() { - activity = null; - isRequestingPermission.set(false); - rationaleAccepted.set(false); - isShowingNativeDialog.set(false); - listener = EMPTY_LISTENER; + if (activity != null) { + activity = null; + isRequestingPermission.set(false); + rationaleAccepted.set(false); + isShowingNativeDialog.set(false); + listener = EMPTY_LISTENER; + } } /** @@ -275,7 +277,6 @@ private void onPermissionsChecked(Collection permissions) { // the permission is checked. Issues #243 and #221 if (activity != null) { activity.finish(); - activity = null; } isRequestingPermission.set(false); rationaleAccepted.set(false); @@ -317,6 +318,10 @@ private void checkMultiplePermissions(final MultiplePermissionsListener listener return; } + if (activity != null && activity.isFinishing()) { + onActivityDestroyed(); + } + pendingPermissions.clear(); pendingPermissions.addAll(permissions); multiplePermissionsReport.clear();