Peter
Peter

Reputation: 2500

Finish all previous activities from other activity

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 :(

Upvotes: 2

Views: 3523

Answers (2)

MurugananthamS
MurugananthamS

Reputation: 2405

Try this:

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

Upvotes: 0

Jitesh Prajapati
Jitesh Prajapati

Reputation: 2533

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.

Upvotes: 10

Related Questions