BVtp BVtp - 8 months ago 92
Android Question

onRequestPermissionsResult is called infinitely

I'm using a runtime permission request, but there is a problem with that. It seems that the callback method

is called infinitely. So when the user denies the request the app is unresponsive..

the permission dialog reappears everytime the user clicks 'deny'. Only by clicking "never ask again" does it not reappear again.
* When pressing 'allow' it works well - without any problems.

Is there any way to cancel the method being invoked after one time?

if (ActivityCompat.checkSelfPermission( this, Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED )
ActivityCompat.requestPermissions( this, new String[]{ Manifest.permission.ACCESS_FINE_LOCATION }, LOCATION_PERMISSION_CUSTOM_REQUEST_CODE );

public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch( requestCode )
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted
} else {
// permission denied


The problem here, as you mentioned in the comments, is that the code that triggers the request permission dialog is being called in the onResume method.

When the request dialog permission finishes, the runtime calls onResume on the activity that triggered it, just as any dialog-themed activity would.

In your case, refusing the permission would trigger a call to onResume again, which would once again display the dialog and cause an endless cycle.

Moving this permission request to onCreate, or some other flow will solve your problem.