5

I have a navigation graph like this

navigation graph

It's a folder/file listing app, when click a folder it will navigate to the same fragment with new instance by the action defined by the graph. After I navigate to some folders and currently in Folder D, a breadcrumb of buttons like below.

Root -> Folder A -> Folder B -> Folder C -> Folder D

When I click on Folder B on the breadcrumb, how can I pop or navigate back to the "Folder B" fragment that is in the back stack?

Edit: Navigation code

// Handle click a folder, navigate to new listing fragment
private fun onItemClick(
    adapter: BaseQuickAdapter<Any, BaseViewHolder>,
    view: View,
    position: Int
){
    val item = adapter.getItem(position) as? CloudFile ?: return
    if (item.isDirectory){
        findNavController().navigate(R.id.action_cloudFileListing, bundleOf(ARG_CLOUD_FOLDER to item), getNavOptions())
    }
}

private fun getNavOptions(): NavOptions? {
    return NavOptions.Builder()
        .setEnterAnim(R.anim.enter_from_right)
        .setExitAnim(R.anim.exit_to_left)
        .setPopEnterAnim(R.anim.enter_from_left)
        .setPopExitAnim(R.anim.exit_to_right)
        .build()
}
leegor
  • 472
  • 5
  • 15
  • I have same issue. I follow method `navigateUp`, `popBackStack` to find hidden features. Then I find `?.currentDestination?.id` of `NavController` but I don't think that id is correct because that's fragment's id in graph. Hope Google update this future here (maybe get current backstack identifier or override args, notify to previous fragments,...). – dphans Nov 27 '20 at 13:56

0 Answers0