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

MultiPermissionsListener not called when reguest permissions from onPermissionGranted #262

Closed
ShandyukSergey opened this issue Jun 15, 2020 · 4 comments

Comments

@ShandyukSergey
Copy link

Expected behaviour

MultiPermissionsListener called when reguest permissions from onPermissionGranted

Actual behaviour

MultiPermissionsListener is NOT called when reguest permissions from onPermissionGranted

Steps to reproduce

  1. Request any permissions and grand them
  2. Request another permissions inside previous onPermissionGranted callback
    Second callback will be never notify. This behaviour was different in 2.4.0 version. Find sample code below. READ_CALENDAR listener will not be notify.
Dexter
        .withContext(context)
	.withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
	.withListener(new MultiPermissionsListener() {
		@Override
		public void onPermissionGranted() {
			Log.d("LOG", "onPermissionGranted: WRITE_EXTERNAL_STORAGE");
			Dexter
					.withContext(context)
					.withPermissions(Manifest.permission.READ_CALENDAR)
					.withListener(new MultiPermissionsListener() {
						@Override
						public void onPermissionGranted() {
							Log.d("LOG", "onPermissionGranted: READ_CALENDAR");
						}

						@Override
						public void onPermissionDeny() {
							Log.d("LOG", "onPermissionDeny: READ_CALENDAR");
						}
					})
					.check();
		}

		@Override
		public void onPermissionDeny() {
			Log.d("LOG", "onPermissionDeny: WRITE_EXTERNAL_STORAGE");
		}
	})
	.check();

Version of the library

6.2.0

@haliltprkk
Copy link

I am facing the same issue, as well

@haliltprkk
Copy link

I have noticed it is about these two libraries that I have used for mediation over iron source advertisement

implementation 'com.ironsource.adapters:vungleadapter:4.3.1'
implementation 'com.vungle:publisher-sdk-android:6.5.3'

it is weird but when I remove these two it started to work normally 🤔

@binarynoise
Copy link
Contributor

binarynoise commented Jul 5, 2020

It also happens when you start a second dialog very quickly (~1s) after returning to the Activity that requested the permission.

I digged around a bit and found, that the previous DexterActivity gets destroyed delayed (when the UI-Thread is idle again).
In the meantime the new DexterActivity has appeared and registered its callback (aka PermissionListener or MultiPermissionsListener).
Then, after the new DexterActivity has shown up, the UI-/Main-Thread gets idle and the old DexterActivity gets destroyed. In that process the callback is removed even though it has been replaced by a new one.

I think, the issue would be fixed, if the lib would check, if the callback to be removed is still the callback that is expected to be there and has not been replaced.

As a consequence the DexterActivity should pass itself to onActivityDestroyed when it gets destroyed and the Dexter instance should check in its onActivityDestroyed that the current activity is the activity that called the onActivityDestroyed:

void onActivityDestroyed(Activity activityThatCalledOnActivityDestroyed) {
    if (activity == activityThatCalledOnActivityDestroyed) {
      ...
    }
}

that would also imply the null-check

@binarynoise binarynoise mentioned this issue Jul 5, 2020
2 tasks
@pedrovgs
Copy link
Contributor

pedrovgs commented Jul 7, 2020

Thanks for the fix @binarynoise I'm releasing a new version with your fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants