Clear backstack of application in android on butto

2019-09-14 22:41发布

问题:

I am developing app in which i want clear all my back-stack on click of log out button. i have searched and tried many solutions given but its not working for me. please if anyone can help me that would be appreciated.

i have tried following code on click of log out button

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

and also tried following code in manifest file

android:launchMode="singleTop"

Thank you in advanced

Thanx to all of you for your valuable reply

i have found one solution and tried this again was worked for me fine

Intent intent = new Intent(Settings.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | 
                Intent.FLAG_ACTIVITY_CLEAR_TASK |
                Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();

回答1:

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TASK);

above is working for me but Intent.FLAG_ACTIVITY_CLEAR_TASK is available from API 11



回答2:

use in manifest android:noHistory="true"