Reputation: 12123
So for example I have two fragments:
When I open link from email it opens my app activity (recreats it if was already opened), then opens start destionation fragment and then opens deep link fragment and when I press back button it returns to start destionation fragment but I don't want such behaviour, I want it to close app instead, so fragment deep link behave as a start destination fragment
Upvotes: 3
Views: 1006
Reputation: 1305
You can do this in several ways:
If you can change your start destination, use the deeplink fragment as start destination, but I guess you have some logic in your start destination and want to navigate to the deeplink programmatically under specified conditions. In that case this solution is not applicable.
by popping the backstack before navigating programmatically to the deeplink:
// remove start destination fragment
findNavController().popBackStack()
findNavController().navigate(Uri.parse(<your_deeplink>))
requireActivity().finish()
from the fragment to kill the Activity. This medium post explains in the detail the onBackPressDispatcher
callback.Upvotes: 1