What should I do if I want to kill all previously generated activities?

Asked 2 years ago, Updated 2 years ago, 148 views

The situation is... There are 6 activities including Home, Screen 1 to Screen 5. When you launch the app, you start with

Home exists and ->screen1->screen2->screen3->...Go to ->screen5.

I want to create a common logout button for all of the above activities, and when the user clicks the logout button, I want to end all activities and display a new Login activity. I tried almost all FLAG_ACTIVITY and searched the stack overflow answers, but I couldn't find a solution. I can't use FLAG_ACTIVITY_CLEAR_TASK because it's Android version 1.6.

Is there a way to solve it?

android android-activity

2022-09-22 22:29

1 Answers

Intent intent = new Intent(getApplicationContext(), Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

Do it like this.

FLAG_ACTIVITY_CLEAR_TOP is a flag that, if the same activity exists in the stack as the one you are trying to create, terminates all activities on the same activity and replaces the existing activity with the newly created activity.


2022-09-22 22:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.