0

I have a LoginActivity as my launcher screen. And SettingsActivity as my fifth screen.

I have a logout button in settings screen. On clcik of this button, how can i go to Screen-1 (i.e LoginActivity) by clearing all remaining activities (i.e 2nd, 3rd, 4th) from activity stack?

Note : i have finished LoginActivity but not remaining activities. Thanks in advance

Shrikant Ballal
  • 7,067
  • 7
  • 41
  • 61
user1670443
  • 461
  • 2
  • 6
  • 17

1 Answers1

2

Simple, set an onclick on your logout button and then add this to your intent:

Intent newIntent = new Intent(this, login.class);

    newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    startActivity(newIntent);
    finish();

This should clear your entire stack above login.class

And if you're feeling real fun today, add

    newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

Which will get rid of that annoying "show the android homescreen" issue on the S3

Vic Vuci
  • 6,993
  • 6
  • 55
  • 90