简体   繁体   中英

Jetpack Navigation Component: Update Bottom Nav Bar on Deep Links

I am testing out the Navigation Component in a sample app. I have a bottom navigation bar with three fragments; say A, B and C. Further, C has another flow connected to it which goes like this; C -> C1 -> C2 -> C3 -> C. No nested graphs in the xml-definition. See image. I have also hooked up the bottom bar according to the documentation.

When running the app and moving around in the app everything works fine, the bottom bar updates the selected item.

However, when adding a deep link to open C2, the app opens C2 but in the bottom bar A is still selected. What am I missing? Should there be any actions connecting A, B and C?

在此处输入图片说明

I had this same issue and I was able to fix it by nesting my nav graphs. In your case, I would take fragments C, C1, C2, C3 and put them in their own navigation graph nested within the main one. Android's Navigation component will then pick this up, see the startDestination of that graph (which you would make as C I'm guessing) and change the bottom navigation accordingly.

This worked for me and has been the only solution that worked for me so far. I believe the integration between notifications (I'm using the NavDeepLinkBuilder ) and the Navigation component is still very new so many features and options are missing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM