Posts

Showing posts with the label Back Stack

Android: Remove All The Previous Activities From The Back Stack

Answer : The solution proposed here worked for me: Java Intent i = new Intent(OldActivity.this, NewActivity.class); // set the new task and clear flags i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(i); Kotlin val i = Intent(this, NewActivity::class.java) // set the new task and clear flags i.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(i) However, it requires API level >= 11. Here is one solution to clear all your application's activities when you use the logout button. Every time you start an Activity, start it like this: Intent myIntent = new Intent(getBaseContext(), YourNewActivity.class); startActivityForResult(myIntent, 0); When you want to close the entire app, do this: setResult(RESULT_CLOSE_ALL); finish(); RESULT_CLOSE_ALL is a final global variable with a unique integer to signal you want to close all activities. Then define every activity's onActivityRe...