Search code examples
androidsharedpreferenceskill

Kill Activity after I log out Android Studio


I have this app which works with a current user saved in shared preferences, the app works fine but when I want to log out, I delete all the shared preferences and then it goes to the login activity, but if press the back button it goes back to my app's home activity. So, my question is there is a way to kill al the activities and history in Android Studio.


Solution

  • Try to start your Login Activity with flags:

    Intent intent = new Intent(this, A.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 
    startActivity(intent);
    

    It would start A as a root activity of a task and finish other activities.