Search code examples
javaandroidandroid-permissions

Permission Requests causes infinite loop in OnResume


In API >= 23, we are required to ask users for permission at run-time. But for some reason, the permissions are causing onResume to be called infinitely. What causes this?

  @Override
protected void onResume() {
    super.onResume();

     ActivityCompat.requestPermissions(MainActivity.this,
     new String[]{Manifest.permission.ANYPERMISSION},1);       

}

 @Override
public void onRequestPermissionsResult(int requestCode,
         String permissions[], int[] grantResults) {
     }  

Solution

  • When you show dialog of permission question, Acitvity goes to onPause, and when dialog hides, it goes to onResume. You have to change place of asking of permission.