Denying Runtime Permission in Android Marshmallow Crashes App
<p>I have trouble with handling runtime permissions in Android Marshmallow and I really need a hand. The problem is when I deny a runtime permission (when the dialog comes up), the app crashes. In more detail, the activity I am currently running is restarted (I just call it an app crash?). </p>

<p>Here is the code:</p>

<pre><code>public void showContacts() {

    if (CommonData.showLogs) {
        Log.d(debugTag, "Show contacts button pressed. Checking permissions.");
    }

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS)
            != PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CONTACTS)
            != PackageManager.PERMISSION_GRANTED) {

        requestContactsPermissions();
    } else {

        if (CommonData.showLogs) {
            Log.d(debugTag, "Contact permissions have already been granted. Displaying contact details.");
        }

        // Do my Stuff
    }
}

private void requestContactsPermissions() {

    if (ActivityCompat.shouldShowRequestPermissionRationale(this,
            Manifest.permission.READ_CONTACTS)
            || ActivityCompat.shouldShowRequestPermissionRationale(this,
            Manifest.permission.WRITE_CONTACTS)) {

        Snackbar.make(rLParent, R.string.permission_contacts_rationale,
                Snackbar.LENGTH_INDEFINITE)
                .setAction(R.string.ok, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        ActivityCompat
                                .requestPermissions(ImportContactsActivity.this, PERMISSIONS_CONTACT,
                                        REQUEST_CONTACTS);
                    }
                })
                .show();
    } else {

        ActivityCompat.requestPermissions(ImportContactsActivity.this, PERMISSIONS_CONTACT, REQUEST_CONTACTS);
    }
}

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


    if (requestCode == REQUEST_CONTACTS) {

        if (PermissionUtil.verifyPermissions(grantResults)) {

            // Do my Stuff
        } else {



            Snackbar.make(rLParent, R.string.permissions_not_granted,
                    Snackbar.LENGTH_SHORT)
                    .show();

        }

    } else {
        Log.d(debugTag, "Contacts permissions were NOT granted.");
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

}
</code></pre>

<p>What am I doing wrong here?
Any help would be greatly appreciated. Thank you very much!</p>