Q:

Android Intent Clear Top not working

I want to hit an intent to my HomeScreenActivity and clear all the activity that are alive in the Stack, below is the intent code:
Intent intent = new Intent(activity, HomeScreenActivity.class);
    if (Build.VERSION.SDK_INT >= 11) {
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    startActivity(intent);
    finish();

The stack is not getting cleared and when i press the back key, all the previous activity are shown, which is not the expected result.
Please help!
Thanks in advance.

A:

Use both flags at the same time:
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

First flag creates new activity when it isn't available in the current task (stack of activities) or reuses existing one. Second flag clears a task associated with requested activity.

