The functionality I want to model in my Android app is, that if the user does login, he gets forwarded to the main menu (MainMenuActivity
). From here and everywhere else where I provide a button for it in the app, he must be able to logout, which should send him back to the login screen (LoginActivity
) and finish all the activities above on the stack. I achieve this by not destroying the LoginActivity after a login and at logout calling:
Intent intent = new Intent(this, LoginActivity.class);
// Clean up all other activities.
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Also I want that the user can not go back with the backbutton form the main menu to the loginscreen. So I did overwrite the method onBackPressed()
in my MainMenuActivity
. Instead I want that when the user is pressing the backbutton from the main menu, the app does terminate (just like its the last activity on the stack). How can I achieve this?
I did read about several other approaches, for example finishing the LoginActivity after the login was performed and then later do it like described here:
https://stackoverflow.com/a/3008684/1332314
But I'm not quite sure if this is a proper solution, just read the comments below the post.