Clear your current Activity stack and launch a new Activity
suggest changeTo clear the current activity stack and open another activity (for example, log out and open a login screen), use one of these approaches.
1. API 16 and later
finishAffinity() finishes every activity in this task that shares this activity's affinity. It does not start the next screen. Start the login activity yourself. If that login activity is in the same task and has the same affinity, start it in a way that keeps finishAffinity() from finishing it too, or use the flags in the next approach.
2. API 11 through 15
Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents