Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) {
     }  
like image 611
grantespo Avatar asked Apr 28 '17 13:04

grantespo


1 Answers

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.

like image 127
Tomasz Czura Avatar answered Nov 11 '22 16:11

Tomasz Czura