i am adding certain permissions to my app to allow access to camera for example and everything is working fine. but when i minimize the app and disable the permission then open the app, the app crashes without asking me to re-enable the permission(until i close the app and then open it). how can i fix this error so that the app dont crash and ask again for permission or safe restart to ask for permissions.
here is my code
in the main activity:
onCreate:
 if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.CAMERA},
                    GlobalVariables.MY_PERMISSIONS_REQUEST_CAMERA);
        }
@Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode)
        {
            case GlobalVariables.MY_PERMISSIONS_REQUEST_CAMERA:
            {
                if (grantResults.length <= 0
                        || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
                    globalVariables.ShowOKAlert("Error","Please Accept All Requested Permissions or the app wont function properly",this,false);
                }
                return;
            }
        }
    }
the activity implements ActivityCompat.OnRequestPermissionsResultCallback
 
     
     
    