I'm trying to use popUpTo
as part of configuring an action in androidx navigation to make sure the back button on the next screens returns to the specified fragment ID.
The problem is the fragment I want to navigate back to is defined as the startDestination
of a nested graph. I would expect to be able to specify the ID of the nested graph in popUpTo
, so that I don't have to link directly to a child fragment's ID, which I understand to be bad practice, if even not an error.
However, the only way to get the behavior I desire is by setting popUpTo
to the ID defined as startDestination
in the nested graph. Specifying the nested graph ID instead jumps over the fragments defined therein.
I could not find specific guidance on how to use popUpTo
with nested graphs. Could anyone provide more details?
I would expect to be able to specify the ID of the nested graph in popUpTo, so that I don't have to link directly to a child fragment's ID, which I understand to be bad practice, if even not an error.
This should work correctly. If this does not work, it means something else is going wrong.
In my case, it turned out that elsewhere in the codebase the backQueue
of NavController
was manipulated manually (.clear()
) was called.
After removing the offending code, I could update my popUpTo
to refer to the nested graph ID, and the backstack got cleared as expected.