wasaig
wasaig

Reputation: 666

Clearing stack including activities in different tasks

I have a main activity A. There are two scenarios

1) A launches B. B has launchmode singleTask and is launched with FLAG_ACTIVITY_NEW_TASK. now I have a menu option in B which performs a delete operation and starts the activity A.

2) A launches B, which launces C it also contains the menu option to perform delet opereation.

I want A to be started with clearing the stack in both the scenarios but the activities belonging to another task still present there I am stuck is there a way to clear the stack.

Upvotes: 5

Views: 407

Answers (4)

dreamtale
dreamtale

Reputation: 2913

My method can not meet your goal A to be started with clearing the stack,But when user choose delet opereation and start B from A again the task that include A and B will be reset.

Use the flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET to mark the task will be clear when needed when you first start activity B from A, then if user choose delet opereation menu item from B or C, you set a flag, so next time from A(A should be single_task launch mode in manifest), you use the flag FLAG_ACTIVITY_RESET_TASK_IF_NEEDED to start B. This flag will clear B and all top of the B.

Hope this will help you :)

Upvotes: 0

Kéza
Kéza

Reputation: 203

Why not finishing B and C before calling A again?

finish();

Upvotes: 0

Tofeeq Ahmad
Tofeeq Ahmad

Reputation: 11975

If i talk about your second scenario then FLAG_ACTIVITY_TOP_CLEARwill clear the stack..

And your stack now will be only A instead of A-B-C-A.

and in second case AFAIU your problem you have only two activity A and B so if you want to restart A then after restarting A manually finish B.

Hope you got some trick.

Another thing if you have activity with launchmode=SingleTask then you can use flag_activity_brought_to_front.

That will act like 

A-B-c to A

Upvotes: 0

jeet
jeet

Reputation: 29199

try using following code on delete opereation on both B and C activity

    Intent intent=new Intent(B.this, A.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

Upvotes: 1

Related Questions