我正在使用标志 FLAG_ACTIVITY_SINGLE_TOP
和 FLAG_ACTIVITY_CLEAR_TOP
返回到之前的“标准”活动。我使用 FLAG_ACTIVITY_SINGLE_TOP 来防止重新创建新实例。但我发现标志 FLAG_ACTIVITY_SINGLE_TOP
被忽略,活动已完成并重新创建。
-
这是我在文档中找到的内容。 FLAG_ACTIVITY_CLEAR_TOP:它表示您可以添加 使用 FLAG_ACTIVITY_CLEAR_TOP
防止“完成 - 重新创建”时,使用 FLAG_ACTIVITY_SINGLE_TOP
。
-
这是另一个文档。 FLAG_ACTIVITY_CLEAR_TOP :
<块引用>
注意:如果指定活动的启动模式是“标准”,它也会从堆栈中删除,并在其位置启动一个新实例来处理传入的意图。这是因为当启动模式为“标准”时,总是会为新意图创建新实例。
我误解了第一个文档吗?
I'm using flag FLAG_ACTIVITY_SINGLE_TOP
and FLAG_ACTIVITY_CLEAR_TOP
to go back to my previous "standard" activity. I use FLAG_ACTIVITY_SINGLE_TOP
to prevent re-creating a new instance. But what I found is that the flag FLAG_ACTIVITY_SINGLE_TOP
is neglected and the activity is finished and re-created.
-
Here is what I found in docs. FLAG_ACTIVITY_CLEAR_TOP: It says that you can add FLAG_ACTIVITY_SINGLE_TOP
when using FLAG_ACTIVITY_CLEAR_TOP
to prevent "finish - recreate".
-
Here is another doc. FLAG_ACTIVITY_CLEAR_TOP:
Note: If the launch mode of the designated activity is "standard", it too is removed from the stack and a new instance is launched in its place to handle the incoming intent. That's because a new instance is always created for a new intent when the launch mode is "standard".
Did I misunderstand the first doc?
发布评论
评论(3)
文档表明 FLAG_ACTIVITY_CLEAR_TOP 就是您需要设置的全部内容。但实际上您必须同时设置两者以防止再次创建活动。
这在我的例子中起到了作用:(主要是我想返回的活动)
The documentation suggests that FLAG_ACTIVITY_CLEAR_TOP is all you need to set. But you actually HAVE to set both to prevent the activity from being created again.
This did the trick in my case: (Main being the activity that I wanted to return to)
这一个可能会有所帮助: Android Intent .FLAG_ACTIVITY_SINGLE_TOP 和 Intent.FLAG_ACTIVITY_CLEAR_TOP
This one could be helpful: Android Intent.FLAG_ACTIVITY_SINGLE_TOP AND Intent.FLAG_ACTIVITY_CLEAR_TOP
检查这个。
意图.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|意图.FLAG_ACTIVITY_SINGLE_TOP)
Check this one.
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|Intent.FLAG_ACTIVITY_SINGLE_TOP)