如何控制机器人回栈 [英] How to Control Android back stack

查看:128
本文介绍了如何控制机器人回栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有

A-> B-> C-> D->电子

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

在Android的回堆栈。我希望能够要回下列之一:

In android back stack. I want to be able to get back to one of the following:

A->B->C
A->B
A

我怎样才能做到这一点?但愿不会强制后退按钮的点击。

How can I achieve this? Hopefully without forcing back button clicks.

推荐答案

从Android上的任务并返回堆栈你可以看到所有其他的方式来推出一个活动,你可以确保这种行为只能用 FLAG_ACTIVITY_CLEAR_TOP 在你的意图的标志。

Using the image and information from the official developers page on Android tasks and back stack you can see that of all other ways to launch an Activity you can ensure such behavior only using the FLAG_ACTIVITY_CLEAR_TOP in your Intent flags.

您定期备份按钮收益为:

Your regular back button proceeds as:

但是,当你指定这个标志,你会得到一个行为像你所需要的,在<一给出一个例子href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP">this来源:

But when you specify this flag, you get a behavior like you need, as given by an example at this source:

考虑由活动的任务:A,B,C,D。若D电话   startActivity()与解析的组件的意图   活动B,然后是C和D将完成和B接收定   意图,导致堆栈现在是:A,B

consider a task consisting of the activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then C and D will be finished and B receive the given Intent, resulting in the stack now being: A, B.

这篇关于如何控制机器人回栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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