Home:ALL Converter>Android Navigation Component popupTo self

Android Navigation Component popupTo self

Ask Time:2022-01-24T23:24:59         Author:Jan Maděra

Json Formatter

I'm using Navigation Component to navigate in my app. I'm working with tree structure and I'm navigating users node by node -> Node == NodeFragment. But now I'm struggling with back navigation to particular node.

E.g.: Image navigation stack with look like this A -> B -> C -> D when user wants to navigate from node D directly to node B I want to popup fragment C, D and go directly to B?

E.g.: You can imagine something like navigating trough folder structure where you are navigation the same fragment again and again. And then you want to go back to particular folder which is not parent of the current one.

But I don't know ho to achieve it with Navigation Component. For navigation I'm using self action. Thanks in advance.

<fragment
    android:id="@+id/nodeFragment"
    android:name="com.example.NodeFragment">

    <action
        android:id="@+id/action_chatbotBuilderChildrenFragment_self2"
        app:destination="@id/nodeFragment" />
        
</fragment>

Author:Jan Maděra,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/70836254/android-navigation-component-popupto-self
Jan Maděra :

So I found some kind of workaround solution which is pretty simple. It seems that calling NavController.navigateUp() multiple times in sort period of time works just fine. I'm not sure if this is the right solution but it solves my issues.\nI was also supprise that even my fragment transition wasn't break after call NavController.navigateUp() multiple times.\nCode example:\nrepeat(numberOfPopUps) {\n findNavController().navigateUp()\n}\n",
2022-01-25T08:26:23
yy