【问题标题】:Back Stack And Intent Flag Not working返回堆栈和意图标志不起作用
【发布时间】:2018-05-07 04:55:04
【问题描述】:

我的应用启动器是活动 A,然后用户转到活动 B,然后是活动 C,然后是活动 D。如果用户从 D 执行某些操作,则用户应重定向到活动 E。

像 A->B->C->D->E

现在如果用户从活动 E 按下返回按钮,那么他应该移动到活动 A。我如何设置意图标志来实现这一点。

提前致谢

【问题讨论】:

标签: android android-intent launchmode


【解决方案1】:

你可以试试..

@Override
public void onBackPressed() {
    // your code.
     Intent intent = new Intent(this, A.class);
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
}

【讨论】:

    【解决方案2】:

    试试,

    @Override
    public void onBackPressed() {
       Intent intent = new Intent(E.this, A.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK  | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }
    

    【讨论】:

    • NEW_TASK 在这里不是必需的。 CLEAR_TOP 就足够了。
    【解决方案3】:

    使用这个

    @Override
    public void onBackPressed() {
        Intent intent = new Intent(this, A.class);
        startActivity(intent);
        finish();
    }
    

    【讨论】:

    • 这只会在E 的现有实例之上启动另一个A 实例。可能不是 OP 想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 2020-10-27
    • 2021-12-02
    • 2011-05-17
    • 2014-04-06
    • 2012-07-17
    相关资源
    最近更新 更多