I have a log in system in my app, and I would like to make it so that once the user logs into their account the back stack get's cleared, so they cannot see the log in activity, unless they click on the log out button in the main activity. How would I accomplish this?
any help would be greatly appreciated.
Use finish()
method to destroy your login activity after intent. It'll be removed from stack as well.
Intent i = new Intent(this, YourAccountActivity.class);
startActivity(i);
// destroying your current activity
finish();
If you don't want to put this activity in the stack, you can also use
android:noHistory="true"
in AndroidManifest.xml
When you change the activity, this activity won't be in the stack.
A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it.
Another option is to use IntentFlags.
Intent i = new Intent(this, YourAccountActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);