I just recently learned how to clear the backstack in Android. I have two activities, one for login (LoginActivity) and one to use the application (MainActivity). It consists of a bunch of fragments. This is the code I used to start the MainActivity
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish(); // call this to finish the current activity
Everything works fine, when I'm on the MainActivity and I press the home
button, the application closes. When I open it back up, it opens the MainActivity. But when I press the back
button, it's closing the application and when I open it back up, the LoginActivity is opening. How do I override the back
button so it behaves the same as the home
button.