Look at the stack of FragmentManager. It has the ability to search / record records in a stack of fragments. You may need some logic, for example: if the user requests a fragment located at the top of the stack (previous fragment), exit this fragment (go back), otherwise create a new one.
This will create:
A (user asks for B) A->B (user asks for A again) A
.. but it doesn’t hurt
A (user asks for B) A->B (user asks for C) A->B->C (user asks for A) A->B->C->A
This will require rewinding the stack back to “A” from “C,” which you can do .. but then if so, you should probably unconditionally pop out the fragment stack before starting a new fragment (IE No back stack in general ..)
source share