Hi this could go in a few channels but I am hoping...
# compose
d
Hi this could go in a few channels but I am hoping for a Compose first solution here.. What’s the Compose way to handle a deep-link and keep your app/backstack state (ideally?) ? Looks like handleDeepLink clears the backStack one way or another so let’s say you have an an app that let’s the user make payments: • midway through using the app, the user goes to the payment flow which launches a Custom Chrome Tab (as per guidelines). • Payment Completed in Chrome Custom Tab. Deeplink issued to get back in the app. • Deeplink received and handled by the system
handleDeepLink
, back stack seems gone so now the when the user presses back after the payment flow confusingly that closes the app.
This is when using the default implementations -
launchMode
is
standard
, single activity app and
handleDeepLink
is not overriden at all
c
NavigationComponent only adds the destination to which your deeplink is pointing, and the startDestination of the navGraphs in which your deeplink destination is defined. So if you have only one NavGraph then the backstack will look like this:
Copy code
NavGraph.startDestination -> DeeplinkedDestination
NavigationComponent will only include the startDestinations from nested Graphs to your DeeplinkDestination. So if You have a hierarchy of NavGraps like this:
Copy code
NavGraph1
   - NavGraph2
       - DeeplinkDestination
This time your backStack after calling
handleDeepLink
will look like this
Copy code
NavGraph1.startDestination -> NavGraph2.startDestination -> DeeplinkedDestination
Disclaimer: I have never actually tried it, I just read it a few times already and was always surprised it works like this. Source: https://medium.com/swlh/proper-back-stack-on-android-every-time-4a811f8ab78c Otherwise I ususally handle deeplink manually and build the backStack with multiple navigation calls myself, which is not nice, but much easier than creating random nested graphs whenever the requirements for deeplinks change
d
Thanks, yeah the "standard" behaviour seems very weird... I'll go with singleTop until further problems..