Skip to content

Instantly share code, notes, and snippets.

@Bhavdip
Created May 15, 2017 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bhavdip/e0629faedbe2167bc8ceca17db5e69b4 to your computer and use it in GitHub Desktop.
Save Bhavdip/e0629faedbe2167bc8ceca17db5e69b4 to your computer and use it in GitHub Desktop.
[Android Intent Filter] tags:Android
//http://stackoverflow.com/questions/3473168/clear-the-entire-history-stack-and-start-a-new-activity-on-android
In API level 11 a new Intent Flag was added just for this: Intent.FLAG_ACTIVITY_CLEAR_TASK
Just to clarify, use this:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Unfortunately for API lvl <= 10, I haven't yet found a clean solution to this. As per @Ben Pearson's comment, for API <=10 now one can use IntentCompat class for the same. One can use IntentCompat.FLAG_ACTIVITY_CLEAR_TASK flag to clear task. So you can support pre API level 11 as well.
Intent newIntent = new Intent(D.this,B.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(newIntent);
The new IntentCompat should've helped on that, but apparently the flag is ignored for API lower than 11.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment