Im making navigation in my app using navigation component from jetpack.
I have 3 screens in my app, all of them implemented via Fragment:
- search screen
- list screen
- detail screen
When user presses search (on search screen
), app navigates to list screen
loads results and displays them. User selects one of the results and navigates to detail screen
. If there is only one result, app navigates from list screen
to detail screen
automatically, effectively skipping list screen.
The problem is back navigation: when there was multiple results I need to navigate back to list screen
, but if there was only one result I need to navigate back to search screen
. I want just call navigateUp
, but this will take me to list screen
(in all cases) and then forward to detail screen
if there is only one result.
When using FragmentTransaction
directly, we can replace
current fragment with and call addToBackStack
only if we want to return to it later.
When using navigation component we can just navigate
, and it behaves as replace
+ addToBackStack
.
How can I achieve replace-without-adding-to-backstack behavior using architecture component?