问题
In my navigation, I have something like this:
- When I open registrationFragment (in entry_graph) from a deep-link, and finish registration, I am navigated to main_graph (MainFragment).
From there, I can access to menuFragment and click on logOut, which calls:
MainFragmentDirections.actionMainFragmentToEntryFragment()
It opens the registrationFragment instead of loginFragment. I do not expect that since loginFragment is the home fragment on that graph.
When I have similar navigation but not using deep-links, it works as it should, it opens the first fragment in that graph, but with this deep-link flow, it always opens the fragment that was opened by the deep-link, no mater where it is positioned in the navigation graph.
I have searched for solutions on SO and web, but could not find the same problem anywhere.
I have tried removing it manually from back-stack and similar solutions but I could not succeed, it always opens the fragment that was opened by the deep-link in first place.
I am using navigation version 2.1.0, but tested this flow on the currently latest 2.2.0 and it behaves the same.
Does anybody knows if there is a solution for this navigating flow?
回答1:
How do navigate in step#2? I tried the same flow and it worked when I used the code described here.
Basically this is the code
PendingIntent pendingIntent = new NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.android)
.setArguments(args)
.createPendingIntent();
As described in the doc, when you navigate using intent, the back-stack is reset, and populated with the home fragment of each previous graph. Just make sure the required back-stack actually described correctly in the nav_graph xml - each home fragment opens a new indent.
Hope it works for you :)
来源:https://stackoverflow.com/questions/60618015/android-navigation-after-deeplink-navigation-to-second-fragment-open-first-fr