GithubHelp home page GithubHelp logo

Using checkPermissions() prompts for first request, but not subsequent requests received while waiting for user about android-permissions HOT 5 CLOSED

mikejeep avatar mikejeep commented on July 16, 2024
Using checkPermissions() prompts for first request, but not subsequent requests received while waiting for user

from android-permissions.

Comments (5)

nishkarsh avatar nishkarsh commented on July 16, 2024 1

@mikejeep This should be fixed in version 0.1.7. Please upgrade the dependency to this version and it should work fine.

from android-permissions.

nishkarsh avatar nishkarsh commented on July 16, 2024

The scenario where a permission dialog is being shown and another permission is asked later is explicitly handled by the library and another permission dialog gets stacked up for the latter permission. However, in specific cases where the shown dialogs do not get user input and are leaked due to their parent context getting destroyed (in case the hosting Activity gets destroyed), the library does not recognize and hence it believes the permissions are still pending.

While this can be handled if the lifecycle is being handled properly in the app using the library, it makes sense for the library to also have the capability to know about the dialogs not being shown anymore. I will see how difficult that is and will update on if it can be handled.

Thanks for reporting the behavior!

from android-permissions.

mikejeep avatar mikejeep commented on July 16, 2024

I actually may have found the cause of the issue. In my app's manifest, I used launchMode=singleInstance. When changing that to any other option, the permission prompts from your library appear to stack properly. I need to do more testing to determine if that otherwise negatively impacts my app, but that appears to be a caveat you may want to document for other users.

from android-permissions.

nishkarsh avatar nishkarsh commented on July 16, 2024

@mikejeep Thanks for spending time on this and figuring out the cause. This is a good finding.
I tried this on a minimal app and was able to reproduce the issue.

I am not sure why launchMode=singleInstance will cause this but on doing a bit of research I realized that it should have never worked for showing multiple permission dialogs stacked up (even without the launchMode). The permission dialog is supposed to be shown in a new task but how to show another dialog if another request is made is not handled explicitly. So multiple dialogs were being shown when launchMode=singleInstance was absent due to some implicit handling by android. When the launchMode is present, it works as documented in Android documentation.

The good thing is that now that we know the exact cause, multiple solutions could be tried out. I will spend some time today to fix this. It should then work for your application without changing the launchMode.

from android-permissions.

nishkarsh avatar nishkarsh commented on July 16, 2024

@mikejeep So the exact cause of the issue was at the place where the activity that contains permission dialog(s) was being started.

Whenever a permission is requested, a PermissionActivity is started using FLAG_ACTIVITY_NEW_TASK flag. According to the documentation, while starting an activity with this flag, it searches for all existing tasks for an activity that has intent matching this intent and only if no matching activity is found is when a new task is created for new activity. However, if no taskAffinity is provided for this activity, it is not created in a new task, which was the case here.

When launchMode=singleInstance is provided, any new activity started from there has to start in a new task and that's where the actual documented behavior for FLAG_ACTIVITY_NEW_TASK is noticed. The intent for new permission activity remained same with just different extras due to which it brought back the same task in front without starting another activity.

An immediate solution for this is to make the intents different for different permission requests (different IntentAction would work) which is what I have done for now, but I have a few things in mind which I would implement soon to make this more stable (possibly without the need of starting new tasks).

from android-permissions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.