Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to finish multiple activities on logout android

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.

like image 628
kadhirvel Avatar asked Dec 10 '25 14:12

kadhirvel


1 Answers

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

like image 157
IAmGroot Avatar answered Dec 13 '25 07:12

IAmGroot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!