Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear Activity Stack on Button Click in Android

Tags:

android

I have a question that I have a logout button in my App on which we have called an App login Screen but at this point when user press the Back Button of Android Phone, he entered in the App again without Authentication, which is not desirable. I want when we click on Logout button All previous Activity Stack being cleared or we can say that All previous onPause Activities have to be cleared.

Please Suggest me the right solution for this problem.

Thanks in advance.

like image 940
Sanat Pandey Avatar asked Mar 28 '26 00:03

Sanat Pandey


1 Answers

As far as I understood the login screen would be the first screen after the splash one so if login screen is in stack you can call again login screen like the below to achieve this

Intent launch = new Intent(context, LoginActivity.class);
launch.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(launch);
like image 67
ingsaurabh Avatar answered Mar 29 '26 12:03

ingsaurabh