Skip to content Skip to sidebar Skip to footer

Java.lang.stackoverflowerror When Request For Runtime Permission

I have created a common class PermissionManager for manage all permission from a single place,normaly it's working fine but after upload it showes error report on crash analytics i

Solution 1:

You have an infinite loop which I'm guessing is caused by someone denying Location permission, and selecting the "Never ask agan" checkbox:

enter image description here

This will automatically deny any further requests for the Location permission. In your case this becomes a big problem as PermissionManager::checkPermission() prompts for the permission dialog using showDialogForPermission(), which is automatically declined, which in turn calls onRequestPermissionsResult().

if (shouldShowRequestPermission(context, permission)) {
    MY_REQUESTED_DIALOG = true;
    showDialogForPermission(context, messageTitle, messageDetails, permission, requestCode);
} else {
    /* THIS LINE IS STARTING THE INFINITE LOOP */
    requestPermission(context, permission, requestCode); 
}

Because shouldShowRequestPermission(context, permission) is returning false, MY_REQUESTED_DIALOG is never set to true and the process loops over and over. My advice would be to break out of the permission process if both shouldShowRequestPermission() == falseand your permission is declined in onRequestPermissionsResult().

if (shouldShowRequestPermission(context, permission)) {
    MY_REQUESTED_DIALOG = true;
    showDialogForPermission(context, messageTitle, messageDetails, permission, requestCode);
} else {
    // Gracefully handle the fact that Location permission will never be granted
}

Solution 2:

That stacktrace is symptomatic of an infinite loop.

Post a Comment for "Java.lang.stackoverflowerror When Request For Runtime Permission"