How to Clear or Kill Stack of Activity – Android

Posted on .

When we use to navigate from one Activity to another than the previous values resides in our device stack so Here is  some Tips to clear  or kill it ..

METHOD 1 –

For API level 11 or greater, use FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK flag on Intent to clear or kill all the activity stack.

Intent intent = new Intent(OldActivity.this, NewActivity.class);
// set the new task and clear flags
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent);

 

METHOD 2 –

Simply use  android:noHistory=”true” in AndroidManifest.xml file .

 

 

2 thoughts on “How to Clear or Kill Stack of Activity – Android

Leave a Reply

Your email address will not be published. Required fields are marked *