diff --git a/rxpermission/src/main/java/com/vanniktech/rxpermission/RealRxPermission.java b/rxpermission/src/main/java/com/vanniktech/rxpermission/RealRxPermission.java index 6ab2274..e6049a8 100644 --- a/rxpermission/src/main/java/com/vanniktech/rxpermission/RealRxPermission.java +++ b/rxpermission/src/main/java/com/vanniktech/rxpermission/RealRxPermission.java @@ -189,22 +189,21 @@ void onRequestPermissionsResult(@NonNull final int[] grantResults, @NonNull fina final int size = permissions.length; for (int i = 0; i < size; i++) { - final PublishSubject subject = currentPermissionRequests.get(permissions[i]); + final String permission = permissions[i]; + final PublishSubject subject = currentPermissionRequests.remove(permission); if (subject == null) { - throw new IllegalStateException("RealRxPermission.onRequestPermissionsResult invoked but didn't find the corresponding permission request."); + throw new IllegalStateException("RealRxPermission.onRequestPermissionsResult invoked but didn't find the corresponding permission request for " + permission); } - currentPermissionRequests.remove(permissions[i]); - final boolean granted = grantResults[i] == PERMISSION_GRANTED; if (granted) { - subject.onNext(Permission.granted(permissions[i])); + subject.onNext(Permission.granted(permission)); } else if (!rationale[i] && !rationaleAfter[i]) { - subject.onNext(Permission.deniedNotShown(permissions[i])); + subject.onNext(Permission.deniedNotShown(permission)); } else { - subject.onNext(Permission.denied(permissions[i])); + subject.onNext(Permission.denied(permission)); } subject.onComplete();