How do I remove the last activity from the stack?
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 call
startActivity(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 to share