permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.

Home Page:https://github.com/permissions-dispatcher/PermissionsDispatcher

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

We can't have multiple constructPermissionsRequest within the same fragment

SamYStudiO opened this issue · comments

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.

Here is a user case >

  • you construct 2 permissions
  • you click a button which call the first permission and accept it, everything is fine so far
  • you click again that button PermissionsRequesterImpl detect it is accepted and remove observers
  • you click a second button to call 2 permissions and this time you never get notified beacause there is no more observers

Solution would be to have a unique observer for each PermissionsRequesterImpl

Environment

  • core 4.9.1
  • ktx 1.1.3

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

maybe dont need removeObservers?

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.