Possible Duplicate:
Removing an activity from the history stack
I am looking for a solution to remove the StartActivity from the history stack. The StartActivity is the one that is being started at the beginning. I am using this Class to check some user values and want to redirect the user to the MainActivity if all is correct.
I have tried to set a flag:
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
but this does not do what it should.
App starts -> StartActivity -> MainActivity -> PRESS back -> the app should end
it does:
App starts -> StartActivity -> MainActivity -> PRESS back -> StartActivity
Thank for your help!
Edit: This is the code i am using to start the MainActivity:
Intent i = new Intent(context, DashBoardActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
You should use FLAG_ACTIVITY_NO_HISTORY
when starting StartActivity to achieve described behaviour.
The same you may achieve if you set noHistory
attribute to true
in your AndroidManifest.xml.
You can simply call finish() after you start the MainActivity.
Intent i = new Intent(context, DashBoardActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With