user155542
user155542

Reputation: 501

How remove last activity from the stack?

I have 3 activitys (A, B, C), the flow is:

A -> B -> C

when i click to back, the flow is:

C -> B -> A

but i want this:

C -> A

not

C -> B -> A

how?

Upvotes: 3

Views: 1362

Answers (1)

George Rappel
George Rappel

Reputation: 7198

There are a few ways to do this.


If you know which activity you don't want to remove from the stack, all you have to do is call finish() after your call startActivity(intent) to the next activity, so this activity will be excluded from the flow, see the example below:

Intent intent = new Intent(...);
startActivity(intent);
finish();

If the decision will happen based on an interaction with the user, you can call startActivityForResult() to start the next activity, and when the activity ends, you have to return a RESULT value.

Here's a good documentation about how to use startActivityForResult(): http://developer.android.com/training/basics/intents/result.html

Upvotes: 5

Related Questions