【问题标题】:Clear backstack of application in android on button click点击按钮清除android中应用程序的backstack
【发布时间】:2014-01-16 11:03:10
【问题描述】:

我正在开发应用程序,我想在单击注销按钮时清除我所有的后台堆栈。 我已经搜索并尝试了许多给出的解决方案,但它对我不起作用。 请如果有人可以帮助我,将不胜感激。

我在点击注销按钮时尝试了以下代码

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

并且还尝试了清单文件中的以下代码

android:launchMode="singleTop"

在此感谢您

感谢大家的宝贵回复

我找到了一个解决方案并再次尝试对我来说很好

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

【问题讨论】:

    标签: android android-intent android-manifest


    【解决方案1】:
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    

    以上对我有用,但Intent.FLAG_ACTIVITY_CLEAR_TASK 可从 API 11 获得

    【讨论】:

      【解决方案2】:

      在清单中使用 android:noHistory="true"

      【讨论】:

      • 谢谢你的回答,但我已经尝试过了,它不适合我
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多