简体   繁体   English

在按钮上单击清除android中的应用程序的堆栈

[英]Clear backstack of application in android on button click

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();
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 上面的代码对我Intent.FLAG_ACTIVITY_CLEAR_TASK ,但是可以从API 11获得Intent.FLAG_ACTIVITY_CLEAR_TASK

在清单android:noHistory =“ true”中使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM