Complete all previous activities from another activity

anyone can help me with my task I have one actvitiy where I open a new new Intent activity, and than in this new activity I open new intentions again (previsios actions do not close, so I can return to them when I click on device). I want to write an “exit button” and start a new activity, I can close only one previsios activity, but pre-previsios is still open. ideally - MainActivity → SettingsActivity → LogoutActivity (here we have to go back to loginActivity) I was judged

mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

but no luck :(

-2
source share
2 answers

try this solution.

 Intent i = new Intent(FirstActivity.this, SecondActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); 

hope this helps.

+5
source

Try the following:

  Intent intent=new Intent(currentActivity.this,TargetActivity.class); Bundle bundle = new Bundle(); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); 
0
source

All Articles