Clear backstack of application in android on butto

2019-09-14 21:53发布

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();

2条回答
2楼-- · 2019-09-14 22:28

use in manifest android:noHistory="true"

查看更多
做个烂人
3楼-- · 2019-09-14 22:42
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

查看更多
登录 后发表回答