【问题标题】:How to Clear the Stack and close the application如何清除堆栈并关闭应用程序
【发布时间】:2013-06-09 12:33:51
【问题描述】:

我想通过在我的应用程序中按下退出按钮来清除堆栈并关闭应用程序。所以当我再次打开应用程序时,我需要从第一个活动启动应用程序。

我正在使用以下语句,但这些语句不起作用。我不想使用启动模式单任务。

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

【问题讨论】:

    标签: android android-activity


    【解决方案1】:

    关闭之前的所有活动如下:

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("Exit me", true);
    startActivity(intent);
    finish();
    

    然后在 MainActivity onCreate() 方法中添加这个以完成 MainActivity

    if( getIntent().getBooleanExtra("Exit me", false)){
        finish();
    }
    

    还有check out this link

    【讨论】:

    • @Crusader-我在我的应用程序的第 10 个屏幕上。如果我在这里按下退出按钮,我不想导航到主要活动,但我想清除所有堆栈,我想导航到android home,当我再次打开应用程序时,我想从启动开始。感谢您的上述建议。
    猜你喜欢
    • 2012-05-12
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 2015-04-13
    相关资源
    最近更新 更多