Bring the front of an existing fragment

I have an application with n buttons. Each button creates a new fragment and attaches it to the view. Therefore, if I touch the buttons A, B, C in this order, the fragments FA, FB and FC are created and added:

FA, FB, FC

Now, if I press A again, a new fragment is created and added, so the stack becomes the following:

FA, FB, FC β†’ FA, FB, FC, FA

Is there a way to restore an existing fragment from the stack (if any) and bring it to the fore? Therefore, if I have a stack

FA, FB, FC

and press the "A" button again, the FA fragment is removed from the back and placed in the foreground:

FA, FB, FC β†’ FB, FC, FA

and if I press "C", the stack will become

FB, FC, FA β†’ FB, FA, FC

Thanks in advance.

+4

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


All Articles