安卓:没有保存到堆栈开放活动 [英] Android: open activity without save into the stack

查看:152
本文介绍了安卓:没有保存到堆栈开放活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个活动:主要和列表

I have 2 activities: Main and List.

从主,你可以打开列表;从列表中可以打开主。

From Main you can open List; from List you can open Main.

我想它,使表的每一个开放做的不是获取保存在历史。因此,pressing从主回来的不能返回列表。

I'd like it so that every opening of List does not get saved into the 'history'. So, pressing back from Main cannot return to List.

这可能吗?

推荐答案

在开始你的列表中的活动,设置它的 意图 像这样的标志:

When starting your list's Activity, set its Intent flags like so:

Intent i = new Intent(...); // Your list's Intent
i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY); // Adds the FLAG_ACTIVITY_NO_HISTORY flag
startActivity(i);

的<一个href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NO_HISTORY"><$c$c>FLAG_ACTIVITY_NO_HISTORY标志保持新的活动被添加到历史堆栈。

The FLAG_ACTIVITY_NO_HISTORY flag keeps the new Activity from being added to the history stack.

注:由于@Sam指出的那样,你可以使用 i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 代替。没有功能上的差异。

NB: As @Sam points out, you can use i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); instead. There is no functional difference.

这篇关于安卓:没有保存到堆栈开放活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆