2

any one can help me with my task I have one actvitiy where i open in new Intent new activity , and than in this new activiyt i open again new intent (previsios activities not close, so i can return to them when click back button on device). I want write "exit button" and start new activity , i can close only one previsios activity, but pre-previsios is still open. in ideal its like - MainActivity - > SettingsActivity - > LogoutActivity(here we must back to loginActivity) i was tried

 mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

but no luck with it :(

Peter
  • 2,480
  • 6
  • 39
  • 60
  • use `finish()` method for removing the activity from stack and also update your question with good explanation and code snippet. – Onkar Nene Jul 08 '16 at 13:43
  • its work if only one activity was before, but i have 2-3 activities before. – Peter Jul 08 '16 at 13:48
  • Possible duplicate of [How to clear the Android Stack of activities?](http://stackoverflow.com/questions/4190429/how-to-clear-the-android-stack-of-activities) – Hiren Patel Jul 08 '16 at 13:50

2 Answers2

10

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 it helps.

Jitesh Prajapati
  • 2,533
  • 4
  • 29
  • 51
0

Try this:

     Intent intent=new Intent(currentActivity.this,TargetActivity.class);
        Bundle bundle = new Bundle();
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
BR89
  • 716
  • 1
  • 6
  • 23
MurugananthamS
  • 2,395
  • 4
  • 20
  • 49