How to restart app by closing all the Activity
s that are in stack? Or close all Activity
s open main? (main is already on stack). I mention this because many Activity
clients call each other so they stay open.
As you know, finish();
it just closes the Activity
current one and shows the previous one on the stack.
If you want the app to go to the main screen when you press the "back" button, you can override the method
onBackPressed
like this:This way it will return to
MainActivity
without having anything on the stack, and if you want to close the application you can callonBackPressed
with the following line of code:And so it will exit the application regardless of what it has stored on the stack.
There is a flag that you can pass to the Intent when you go to an activity. The following action removes the previous stored activities from the stack.
I was able to do with the following
This is enough and it works for me.