从后堆栈的Andr​​oid删除活动 [英] Android remove Activity from back stack

查看:144
本文介绍了从后堆栈的Andr​​oid删除活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我很为难做什么与此有关。所以,我有MainActivity,并从那里的活动可以发射到DegreePlanActivity,并从那里另一个活动可以推出EditDegreePlan。我有EditDegreePlan设置为noHistory在AndroidManifest。问题是他们救EditDegreePlan后,启动一个活动来DegreePlan。因此,如果用户presses返回他们要preSS两次去MainActivity了。我想摆脱这使他们只需要preSS一次。我难倒如何做到这一点,虽然。

Okay so I'm kind of stumped on what to do with this. So I have the MainActivity, and from there an Activity can be launched to DegreePlanActivity, and from there another Activity can be launched to EditDegreePlan. I've got EditDegreePlan set to noHistory in the AndroidManifest. The problem is after they save the EditDegreePlan it launches an Activity to DegreePlan. So if the user presses Back they have to press it twice to get to MainActivity again. I want to get rid of that so they only have to press it once. I'm stumped on how to do this though.

如果我在EditDegreePlan设置DegreePlanActivity为noHistory那么他们不能preSS回到它一会儿。

If I set DegreePlanActivity to noHistory then they couldn't press Back to it while in EditDegreePlan.

我试图重写onBack pressed方法和发射的意图MainActivity。问题就在于,他们必须preSS返回多次以退出应用程序,然后。

I've tried overriding onBackPressed method and launching an intent to MainActivity. The problem then is that they have to press Back multiple times to exit the app then.

我应该怎么办?

推荐答案

<一个href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP">FLAG_ACTIVITY_CLEAR_TOP明确你的活动栈,您可以使用code:

FLAG_ACTIVITY_CLEAR_TOP clear your Activity stack , you can use the code :

Intent intent = new Intent(this, Activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

记住这个标志清除只是中级活动,例如,如果你有A,B,C在返回堆栈然后再从C活性打算到D这个标志这清除返回堆栈和堆栈是A,B,C,D,但如果从活动D访问活动一个使用该标志,B,C,D活动会弹出从堆栈中,你将有只是一个在返回堆栈。

Remember that this flag clears just Intermediate Activities , for example if you have A,B,C in your Back Stack then going from C Activity to D with this flag this does not clear Back Stack and the Stack would be A,B,C,D but if you go from Activity D to Activity A with this flag , B,C,D Activities will pop up from the stack and you will have just A in the Back Stack .

这篇关于从后堆栈的Andr​​oid删除活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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