permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.22k stars 1.44k forks source link

We can't have multiple constructPermissionsRequest within the same fragment #755

Open SamYStudiO opened 2 years ago

SamYStudiO commented 2 years ago

Hello,

I have 2 constructPermissionsRequest (one for location and one for external storage) from the same fragment (i don't make them using the same construct because i want to call them in the right context and so they need to be call at different time).

Problem is the second one will never gets its callbacks called once the first one has been accepted. this is because when you call PermissionsRequesterImpl.launch ALL observers are removed. https://github.com/permissions-dispatcher/PermissionsDispatcher/blob/d7ac8bf6215edeea5c307e4bb0f71524aa3babc6/ktx/src/main/java/permissions/dispatcher/ktx/PermissionsRequesterImpl.kt#L38

Here is a user case >

Solution would be to have a unique observer for each PermissionsRequesterImpl

Environment

hotchemi commented 2 years ago

Thank you so much! would you mind sending a PR?

ColorfulHorse commented 2 years ago

maybe dont need removeObservers?

kimukou commented 1 year ago

PermissionsRequesterImpl

ViewModelProvider(activity).get(PermissionRequestViewModel::class.java).observe

owner is not good

Fragment.constructPermissionsRequest

owner is Fragment better use not actiity and i hope PermissionsRequester add function clear(inner call removeObservers)

Currently, if you implement call with multiple Fragments, it may refer to a Fragment that has already been destroyed, resulting in a crash.