Nicolas Durán
Nicolas Durán

Reputation: 292

Clear ALL activities in back stack

I have this stack:

Login Activity -> Registration Activity

After a successful registration I call this:

Intent i = new Intent(getApplicationContext(),Home.class);
i.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(i);
finish();

And this finish my Registration activity BUT not my Login activity, so my stack stay like this:

Login Activity -> Home Activity

Any advice?

Upvotes: 0

Views: 1838

Answers (3)

Abhay Pratap
Abhay Pratap

Reputation: 1996

use this with intent in order to clear the backtrace activities

Java

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

Kotlin

 var intent = Intent(this, [Your_activity]:class.java)
        intent.flags =  Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
        startActivity(intent)

Upvotes: 1

Nicolas Durán
Nicolas Durán

Reputation: 292

Well, i ended up using this answer

Clear the entire history stack and start a new activity on Android

And that do exactly what Im trying to do

Upvotes: 0

BDRSuite
BDRSuite

Reputation: 1612

To clear activities on the top of the stack ,

Intent i = new Intent(getApplicationContext(), Home.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtra("EXIT", true);
startActivity(i);
finish();

Upvotes: 0

Related Questions