开发者

Make a particular activity as a root activity in stack

i have a set of activities on my stack Say A-->B-->C. when i launch 开发者_运维知识库the activity named 'D' it should get fired as the root activity of my application and all the other activities(A,B,C) should get cleared from my stack once Activity D is launched.Can any one tell me as how to do this


Set root activity

    Intent intent = new Intent(this, DActivity.class);

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    startActivity(intent);


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

Specifically, for your question, one has to use FLAG_ACTIVITY_CLEAR_TASK which will clear any existing task that would be associated with the activity before the activity is started i.e. the activity becomes the new root of an otherwise empty task, and any old activities are finished.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜