简体   繁体   English

popBackStackImmediate与popBackStack之间的区别

[英]difference between popBackStackImmediate vs popBackStack

Could some one please tell me the difference between popBackStackImmediate and popBackStack ? 有人可以告诉我popBackStackImmediatepopBackStack之间的区别吗? I really don't get it and additionally what is the "flag" 0(zero) means in 2nd of popBackStack ? 我真的不明白,而且popBackStack 2nd中的“标志” 0(零)是什么popBackStack

Thank you very much for your helps guys... 非常感谢您的帮助...

popBackStackImmediate() will perform the popping commands immediately in the call. popBackStackImmediate()将在调用中立即执行弹出命令。 The results of which can be verified immediately after the call. 通话后可以立即验证其结果。 It is somewhat slower since all the popping actions are performed within the call. 由于所有弹出操作都是在呼叫内执行的,因此速度稍慢。

popBackStack() will perform the popping commands within the next event loop cycle (ie next draw phase). popBackStack()将在下一个事件循环周期(即下一个绘制阶段)内执行弹出命令。 So it's asynchronous to the rest of the code. 因此,它与其余代码是异步的。 That means the FragmentTransaction will not be removed from the backstack after this is executed. 这意味着FragmentTransaction在执行后不会从后堆栈中删除。 In most cases you don't need the FragmentTransaction immediately popped, so it waits until everything else is finished before it actually happens. 在大多数情况下,你不需要 FragmentTransaction立即弹出,所以它等待,直到它实际发生之前,一切就结束了。 All this happens so fast that the user wouldn't recognize it. 这一切发生得如此之快,以至于用户无法识别。

The flag at the end is unrelated. 末尾的标志无关。 It can currently only be set to POP_BACK_STACK_INCLUSIVE . 当前只能将其设置为POP_BACK_STACK_INCLUSIVE The FragmentManager allows you to set an ID on the backstack. FragmentManager允许您在后堆栈上设置ID。 If you set the flag, then it will pop the FragmentTransaction that match the ID specified until there is one that does not match the ID or the bottom is reached. 如果设置了该标志,则它将弹出与指定的ID匹配的FragmentTransaction ,直到出现一个与ID不匹配或到达底部的ID。 If the flag is not set, then all FragmentTransaction s that don't match the ID are popped until one is reached that does match the ID or the bottom is reached. 如果未设置该标志,那么将弹出所有与ID不匹配的FragmentTransaction ,直到达到与ID匹配的底部或到达底部为止。

popBackStack() will pop the back stack, but it won't perform the pop until slightly later - it posts a message to do it so you don't have to wait for a heavyweight operation to occur. popBackStack()将弹出堆栈,但直到稍后才执行弹出操作-它会发布一条消息来执行此操作,因此您不必等待重量级的操作发生。

popBackStackImmediate() does it right now, before the function returns. popBackStackImmediate()在函数返回之前立即执行此操作。 Its slower and can cause perf issues. 它的速度较慢,可能会导致性能问题。 Use the non-immediate version when possible. 尽可能使用非立即版本。

0 as the second parameter means to use the default behavior (remove the top element in the backstack). 0作为第二个参数表示使用默认行为(删除后堆栈中的顶部元素)。 You can also pass it a series of boolean ORed flags. 您还可以向其传递一系列布尔ORed标志。 The only flag currently supported is POP_BACK_STACK_INCLUSIVE , which changes it to take out multiple fragments. 当前唯一支持的标志是POP_BACK_STACK_INCLUSIVE ,它将更改为取出多个片段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM