From c0af2bd0aaea357592a7410973fb3247f23da72c Mon Sep 17 00:00:00 2001 From: binarynoise Date: Tue, 7 Jul 2020 08:36:22 +0200 Subject: [PATCH] fix #262 (#264) --- dexter/src/main/java/com/karumi/dexter/Dexter.java | 5 +++-- dexter/src/main/java/com/karumi/dexter/DexterActivity.java | 2 +- dexter/src/main/java/com/karumi/dexter/DexterInstance.java | 7 ++++--- .../test/java/com/karumi/dexter/DexterInstanceTest.java | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dexter/src/main/java/com/karumi/dexter/Dexter.java b/dexter/src/main/java/com/karumi/dexter/Dexter.java index d6bb7c65..1f0ed8bf 100644 --- a/dexter/src/main/java/com/karumi/dexter/Dexter.java +++ b/dexter/src/main/java/com/karumi/dexter/Dexter.java @@ -150,14 +150,15 @@ static void onActivityReady(Activity activity) { /** * Method called whenever the DexterActivity has been destroyed. + * @param oldActivity the DexterActivity that was destroyed */ - static void onActivityDestroyed() { + static void onActivityDestroyed(DexterActivity oldActivity) { /* Check against null values because sometimes the DexterActivity can call these internal methods when the DexterInstance has been cleaned up. Refer to this commit message for a more detailed explanation of the issue. */ if (instance != null) { - instance.onActivityDestroyed(); + instance.onActivityDestroyed(oldActivity); } } diff --git a/dexter/src/main/java/com/karumi/dexter/DexterActivity.java b/dexter/src/main/java/com/karumi/dexter/DexterActivity.java index a319a3c1..06b785c5 100644 --- a/dexter/src/main/java/com/karumi/dexter/DexterActivity.java +++ b/dexter/src/main/java/com/karumi/dexter/DexterActivity.java @@ -40,7 +40,7 @@ public final class DexterActivity extends Activity @Override protected void onDestroy() { super.onDestroy(); - Dexter.onActivityDestroyed(); + Dexter.onActivityDestroyed(this); } @Override protected void onNewIntent(Intent intent) { diff --git a/dexter/src/main/java/com/karumi/dexter/DexterInstance.java b/dexter/src/main/java/com/karumi/dexter/DexterInstance.java index 6ec52193..e96bccda 100644 --- a/dexter/src/main/java/com/karumi/dexter/DexterInstance.java +++ b/dexter/src/main/java/com/karumi/dexter/DexterInstance.java @@ -121,9 +121,10 @@ void onActivityReady(Activity activity) { /** * Method called whenever the inner activity has been destroyed. + * @param oldActivity the DexterActivity that was destroyed */ - void onActivityDestroyed() { - if (activity != null) { + void onActivityDestroyed(Activity oldActivity) { + if (activity == oldActivity) { activity = null; isRequestingPermission.set(false); rationaleAccepted.set(false); @@ -318,7 +319,7 @@ private void checkMultiplePermissions(final MultiplePermissionsListener listener } if (activity != null && activity.isFinishing()) { - onActivityDestroyed(); + onActivityDestroyed(activity); } pendingPermissions.clear(); diff --git a/dexter/src/test/java/com/karumi/dexter/DexterInstanceTest.java b/dexter/src/test/java/com/karumi/dexter/DexterInstanceTest.java index bf8e11dd..5ecc12a9 100644 --- a/dexter/src/test/java/com/karumi/dexter/DexterInstanceTest.java +++ b/dexter/src/test/java/com/karumi/dexter/DexterInstanceTest.java @@ -153,7 +153,7 @@ public void onCheckPermissionMoreThanOnceThenThrowException() { givenPermissionIsAlreadyDenied(ANY_PERMISSION); whenCheckPermission(permissionListener, ANY_PERMISSION); - dexter.onActivityDestroyed(); + dexter.onActivityDestroyed(activity); whenCheckPermission(permissionListener, ANY_PERMISSION); verifyRequestPermissions(new String[]{ANY_PERMISSION}, 2);