Make specific activity as root activity on the stack

I have a set of actions on the stack Say A → B → C. when I start an activity called "D" it should be launched as the root activity of my application and all other actions (A, B, C) should be cleared from my stack when "Activity D." starts. Someone tell me how to do this

+8
android stack android-intent android-activity
source share
2 answers

If you look through this documentation http://developer.android.com/reference/android/content/Intent.html , you can see various flags of intent and their use.

In particular, for your question, you need to use FLAG_ACTIVITY_CLEAR_TASK , which will clear any existing task that will be associated with the activity before the start of the action, i.e. the action will become the new root of the empty task, and all old actions are completed.

+5
source share

Set root activity

Intent intent = new Intent(this, DActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); 
+2
source share

All Articles