Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
fix #262 (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
binarynoise authored Jul 7, 2020
1 parent a6db8e8 commit c0af2bd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions dexter/src/main/java/com/karumi/dexter/Dexter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dexter/src/main/java/com/karumi/dexter/DexterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions dexter/src/main/java/com/karumi/dexter/DexterInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -318,7 +319,7 @@ private void checkMultiplePermissions(final MultiplePermissionsListener listener
}

if (activity != null && activity.isFinishing()) {
onActivityDestroyed();
onActivityDestroyed(activity);
}

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

0 comments on commit c0af2bd

Please sign in to comment.