Android 6.0 closing app after requesting permissions causes permissions to be asked for 3 times each
<p>I ran into a strange bug (I think) when trying to update my app to use Android 6.0 permissions. My code is as follows:</p>

<pre><code>public void requestPerms2() 
    boolean gratedPermissions = false;
    PackageManager pm = this.getPackageManager();

    int hasPerm1 = PackageManager.PERMISSION_GRANTED; //Assume granted on low level
    if(android.os.Build.VERSION.SDK_INT &gt; 15) {
        hasPerm1 = pm.checkPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE,
                this.getPackageName());
    }
    int hasPerm2 = pm.checkPermission(
            Manifest.permission.RECORD_AUDIO,
            this.getPackageName());

    if(hasPerm1 != PackageManager.PERMISSION_GRANTED){
        String [] neededPerms = {some.path.here.Manifest.permission.READ_EXTERNAL_STORAGE};
        ActivityCompat.requestPermissions(this, neededPerms , 1);
        gratedPermissions = true;
    }

    if(hasPerm2 != PackageManager.PERMISSION_GRANTED){
        String [] neededPerms = {some.path.here.Manifest.permission.RECORD_AUDIO};
        ActivityCompat.requestPermissions(this, neededPerms , 1);
        grantedPermissions = true;
    }
    if(grantedPermissions)
        System.exit(0);
}
</code></pre>

<p>This is inside a method called from onCreate, and is definitely called only one time (I have some debug statements I took out). However, it will prompt the user for permissions 3 times each. I've tried varying the requested permissions, and it always asks 3 times each. If I comment out the System.exit(0), it works perfectly and asks the user one time per permission. </p>

<p>I ideally want to close the app after getting permissions and forcing a relaunch, since the permissions won't apply until after an app restart. Is there any way to do this without asking the user to allow permissions 3 times each?</p>