从后堆栈的Andr​​oid删除活动堆栈、Andr、oid

由网友(风泊天)分享简介:好了,所以我很为难做什么与此有关。所以,我有MainActivity,并从那里的活动可以发射到DegreePlanActivity,并从那里另一个活动可以推出EditDegreePlan。我有EditDegreePlan设置为noHistory在AndroidManifest。问题是他们救EditDegreePlan后...

好了,所以我很为难做什么与此有关。所以,我有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.

我应该怎么办?

推荐答案

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 .

阅读全文

相关推荐

最新文章