How do I remove the last activity from the stack?

I have 3 activities (A, B, C), stream:

A -> B -> C


when i click on the back button the flow is:

C -> B -> A


but i want this:

C -> A



C -> B -> A




source to share

1 answer

There are several ways to do this.

If you know what activity you don't want to remove from the stack, all you have to do is call finish()

after your callstartActivity(intent)

for the next action, so this action will be excluded from the stream, see example below:
Intent intent = new Intent(...);


If the decision will be based on user interaction, you can call startActivityForResult()

to start the next action, and when the action ends, you must return a RESULT.

Here is some good documentation on how to use startActivityForResult()




All Articles