android – Back navigation after deep link by navigation architecture component-ThrowExceptions

Exception or error:

When I open the app from a deeplink (user clicks on URL) and press back button I expect user to navigate to a previous fragment in my navigation graph but it just exits the app.

The documentation says that back navigation should work the same way as if it the user got to that screen naturally.

Can I somehow specify the desired backstack in my navigation graph? Or can be backstack formed automatically after a deeplink? For older version of the library I found out that after back press it should navigate to the root of my navigation graph but that does not happen.

How to solve:

As mentioned in the documentation :

When a user opens your app via an explicit deep link, the task back stack is cleared and replaced with the deep link destination. When nesting graphs, the start destination from each level of nesting—that is, the start destination from each element in the hierarchy—is also added to the stack.

the start destination of the graph also added to the stack.
So when you click on the back button, the start destination on the graph coming to the top of the stack.

Leave a Reply

Your email address will not be published. Required fields are marked *