Android M permissions close my app

An example of implementing Permissions in any Activity.

SampleActivity.java

public class SampleActivity extends AppCompatActivity{
    private final int PERMISSION_CODE = 1;
    Button button;
    @override
    onCreate(Bundle savedInstance){
        super.onCreate(savedInstance);
        setContentView(R.layout.your_layout);
        button = (Button)findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener(){
            @override
            public void onClick(View view){
                requestPermissionAndContinue();
            }
        });
        //remaining code to continue using the app
        //your actual code should also be in this same class
    }

    private void requestPermissionAndContinue(){
        if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED){
            if(ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)){
                Log.e(TAG, "permission denied, show dialog");
            }else{
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS}, PERMISSION_CODE);
            }
        }else{
            accessContacts();
        }
    }

    private void accessContacts(){
        //your code once you receive permission
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if(grantResults.length > 0 && permissions[0]==PackageManager.PERMISSION_GRANTED){
            accessContacts();
        }else{
             //redirect to settings page or ask permission again
        }
    }
}

Same problem here.

ankit jain was on the track. Removing android:noHistory="true" fixed the N.Park problem.

Although in my case I needed that value to be true, or at least the behaviour that makes (I had a SplashScreen where I managed the permissions, and after moving on, I wanted that Activity out of my stack).

So:

  1. I deleted line android:noHistory="true"

  2. In the activity I manage the permission without problems

  3. After that, I move into the next activity with:

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK );

I faced same issue,check if activity android:noHistory="true" in your Manifest file.