Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whenPermissions not called on api 23 or 25 #2

Open
petrachenicolaedaniel opened this issue Jan 23, 2017 · 2 comments
Open

whenPermissions not called on api 23 or 25 #2

petrachenicolaedaniel opened this issue Jan 23, 2017 · 2 comments

Comments

@petrachenicolaedaniel
Copy link

// called from activity
new Permissive.Request(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
.whenPermissionsGranted(new PermissionsGrantedListener() {
@OverRide
public void onPermissionsGranted(String[] permissions) throws SecurityException {
// given permissions are granted
}
})
.whenPermissionsRefused(new PermissionsRefusedListener() {
@OverRide
public void onPermissionsRefused(String[] permissions) {
// given permissions are refused
}
})
.execute(this);

@jksiezni
Copy link
Owner

Hi,
It's a known issue, which happens if you do not store a strong reference to the listener passed to whenPermission*() method. It's due to weak references used by the library to prevent memory leaks.
So, until a better solution is found, a correct implementation would look like:

private PermissionsGrantedListener onPermissionsGranted = new PermissionsGrantedListener() {
@Override
public void onPermissionsGranted(String[] permissions) throws SecurityException {
// given permissions are granted
}
};
private PermissionsRefusedListener onPermissionsRefused = new PermissionsRefusedListener() {
@Override
public void onPermissionsRefused(String[] permissions) {
// given permissions are refused
}
};
// [...]
new Permissive.Request(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
.whenPermissionsGranted(onPermissionsGranted)
.whenPermissionsRefused(onPermissionsRefused)
.execute(this);

@petrachenicolaedaniel
Copy link
Author

Got it! Thanks

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

No branches or pull requests

2 participants