安卓创建不同backstacks(任务),并返回给他们 [英] Android create different backstacks (tasks) and return to them

查看:154
本文介绍了安卓创建不同backstacks(任务),并返回给他们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了这篇文章:的http://开发商。 android.com/guide/components/tasks-and-back-stack.html

如果我正确地读它,它说,你可以用一个新的活动创建一个新的任务,而旧的任务依然有着backstack。他们还谈到重回老TAKS。但是我没有找到如何实现这一点。

If I read it correctly it says you can create a new task with a new activity while the old task still has a backstack. They are also talking about returning to an old taks. However I did not find how to implement this.

我想:

我有一个抽屉式导航。我想点击一个项目。在背面是pressed它可以追溯到根。但是,如果你点击其他项目中,backstack保存在当前任务。然后,一个新的backstack在此其他项目创建的。再次单击第一个项目。当我想去的backstack的顶部,所以继续你在哪里。

I have a navigation drawer. I want to click an item. When back is pressed it goes back to the root. But if you click another item, the backstack is saved in the current task. Then a new backstack is created in this other item. When clicking the first item again I want to go to the top of the backstack, so continuing where you were.

例如:

  1. 在A1 - > A2 - > A3(抽屉项目点击)(所以backstack为(A1,A2,A3))
  2. 在A1 - > A4 - > A5(最后一个抽屉单击的项目)
  3. A3(随着backstack A1,A2,A3)的

这可能吗?

注:我与活动的工作,它是一个大的应用程序和活动,更易于维护。

NOTE: I work with activities, it is a large app and activities are easier to maintain.

推荐答案

NavigationDrawer 是简化的导航,否则将是复杂和繁琐的管理,无论是目的对于用户和程序员。你的应该采取什么的做的是,当你开始一个新的活动从根活动 A1 ),你应该启动它是这样的:

The purpose of the NavigationDrawer is to simplify navigation that would otherwise be complex and tedious to manage, both for the user and programmer. What you should do is, whenever you start a new Activity from the root Activity (A1), you should start it like this:

Intent intent = new Intent(this, A2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent);

这将确保 A1 始终的的backstack的根源。

This will ensure that A1 is ALWAYS the root of the backstack.

我不知道你有想您所描述的行为,具体是什么原因,但我认为我所上述要适当,该backstack.In优美的处理任何情况下,这将是极具挑战性的实现行为你所要求的。

I don't know what specific reasons you have for wanting the behavior you describe, but I would consider what I have described above to be appropriate, graceful handling of the backstack.In any case, it would be extremely challenging to implement the behavior you are asking for.

这篇关于安卓创建不同backstacks(任务),并返回给他们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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