I am using the following code to obtain read write permissions, however the problem is, by having this piece of code in oncreate, my app starts twice instead of once. How do I fix this?

```
// **check if app has permission 1**//
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!Settings.System.canWrite(this)) {
            requestPermissions(new String[] {
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.READ_EXTERNAL_STORAGE }, 2909);
        } else {
            // continue with your code
        }
    } else {
        // continue with your code
    }

```

here is rest of the code which is outside oncreate-

```
// **check if app has permission 2**//
@Override
public void onRequestPermissionsResult(int requestCode,
        String[] permissions, int[] grantResults) {
    switch (requestCode) {
    case 2909: {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Log.e("Permission", "Granted");
        } else {
            Log.e("Permission", "Denied");
        }
        return;
    }
    }
}

```