Difference between popBackStackImmediate and popBackStack

Can someone tell me the difference between popBackStackImmediate and popBackStack ? I really don't understand it and, besides, what does the β€œflag” mean 0 (zero) means in the 2nd of popBackStack ?

Thanks so much for helping the guys ...

+5
source share
2 answers

popBackStackImmediate() will execute popping commands immediately in the call. The results of which can be checked immediately after the call. It is somewhat slower, since all popping actions are performed within the call.

popBackStack() will execute popping commands in the next cycle of the event loop (i.e. the next stage of drawing). Thus, it is asynchronous with the rest of the code. This means that FragmentTransaction will not be removed from the stack after execution. In most cases, you do not need to call FragmentTransaction right away, so it waits until everything else is complete before it happens. All this happens so quickly that the user does not recognize it.

The flag at the end is irrelevant. Currently, it can only be set to POP_BACK_STACK_INCLUSIVE . FragmentManager allows you to set the identifier in the stack. If you set the flag, it will pull out a FragmentTransaction that will match the identifier specified until one that does not match the identifier is reached, or the bottom is reached. If the flag is not set, then all FragmentTransaction that do not match the identifier are exported until one that matches the identifier or the lower boundary is reached.

+6
source

popBackStack() will pop out the back stack, but it won't pop until a bit later - it sends a message to do this, so you don't have to wait for a hard operation to happen.

popBackStackImmediate() doing this right now before the function returns. It is slower and can cause perforation problems. Use the possible immediate version.

0, since the second parameter means using the default behavior (remove the top element in the backstack). You can also pass him a series of Boolean ORed flags. Currently, only the POP_BACK_STACK_INCLUSIVE flag is supported , which changes it to take out several fragments.

+3
source

Source: https://habr.com/ru/post/1269035/


All Articles