Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove "start"-activity from the history [duplicate]

Tags:

android

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);
like image 898
Mark Avatar asked Apr 26 '11 13:04

Mark


2 Answers

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.

like image 61
Zelimir Avatar answered Sep 20 '22 09:09

Zelimir


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();
like image 43
Flo Avatar answered Sep 21 '22 09:09

Flo