Remove "start" activity from history

Possible duplicate:
Removing activity from the history stack

I am looking for a solution to remove StartActivity from the history stack. StartActivity is the one that starts at the beginning. I use this class to check some user values ​​and want to redirect the user to MainActivity if everything is correct.

I tried to set the flag:

addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

but it does not do what is needed.

 App starts -> StartActivity -> MainActivity -> PRESS back -> the app should end 

he does:

 App starts -> StartActivity -> MainActivity -> PRESS back -> StartActivity 

Thank you for your help!

Edit: this is the code I use to run MainActivity:

 Intent i = new Intent(context, DashBoardActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); 
+8
android
source share
2 answers

You must use FLAG_ACTIVITY_NO_HISTORY when starting StartActivity to achieve the described behavior.

The same thing can be achieved if you set the noHistory attribute to true in your AndroidManifest.xml.

+8
source share

You can simply call finish () after starting MainActivity.

 Intent i = new Intent(context, DashBoardActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); finish(); 
+12
source share

All Articles