In my app i am starting activities one after the another and not finishing any activity before calling another. But when user presses logout button then i want to finish all the activities from the stack and start login activity.
Activity Login(finish & call) --> Activity B --> Activity C--> Activity D --> Logout -->Acitivity Login.
If user presses back key on login activity then he returns to Activity C in my case... but i want to avoid that.
What you should do is call Login activity, and clear all activities above it in the stack.
Intent intent = new Intent(this, Login.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
This will flag it to create a new login activity, not just resume the previous one. And clear all activities above it. (B, C, D).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With