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

      

not

C -> B -> A

      

as?

+3


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(...);
startActivity(intent);
finish();

      


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()

: http://developer.android.com/training/basics/intents/result.html

+3


source







All Articles