遍历堆栈中的活动 [英] Traverse between activities in stack
问题描述
假设我在堆栈中有活动A,B,C的活动实例A1,B1,A2,B2,C1.如何从C1遍历到活动实例B1?
Suppose I have activity instances A1, B1, A2, B2, C1 of activities A, B, C in stack. How can I traverse to Activity instance B1 from C1?
让我们概括一下,B1和C1之间将有'n'个活动.
Let us generalize there will be 'n' number of activities between B1 and C1.
我不想从C1创建B的新实例.
I don't want to create a new instance of B from C1.
推荐答案
对于Android来说,这实际上是一个非常糟糕的体系结构.如果在Activity
上创建多个实例,则无法专门解决它们,例如:返回到ActivityB
的第一个实例". Android不是这样设计的.
This is actually a very bad architecture for Android. If you create multiple instances on an Activity
, there is no way to specifically address them, for example: "Go back to the first instance of ActivityB
". Android isn't designed like this.
您应该避免创建Activity
的多个实例.最好使用相同的实例,并通过交换基础数据并可能在显示器上添加状态转换来创建多个实例的幻觉",以使您看起来好像正在启动另一个Activity
.
You should avoid creating multiple instances of an Activity
. It is beter to use the same instance and just create the "illusion" of multiple instances by swapping out the underlying data and maybe adding a state transition on the display so that it looks like you are starting another Activity
.
另一种可能的解决方案是使用大量startActivityForResult()
并将有关下一步操作的信息返回给调用方Axctivity
.
Another possible solution would be to use a lot of startActivityForResult()
and return information to the calling Axctivity
about what to do next.
有关更多详细信息,请参见(即使这些问题是专门针对使用FLAG_ACTIVITY_REORDER_TO_FRONT
的,但问题仍然基本相同):
For more details see (even though these questions are specifically about using FLAG_ACTIVITY_REORDER_TO_FRONT
, the problem is still basically the same):
多个活动实例和FLAG_ACTIVITY_REORDER_TO_FRONT
使用FLAG_ACTIVITY_REORDER_TO_FRONT
这篇关于遍历堆栈中的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!