Stylianos Gakis
04/08/2023, 10:49 PMWhen 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 <navigation> element in the hierarchy—is also added to the stack. This means that when a user presses the Back button from a deep link destination, they navigate back up the navigation stack just as though they entered your app from its entry point.
So if we deep link into say the schedule screen, the backstack would be [StartupDestination, ScheduleScreen], then pressing back would be for a brief moment [StartupDestination] and since that on launch navigates away and leaves the backstack it’d then be [WhateverItNavigatedTo], which if it’s the same as the previous deep link, it’d in the end end up making the back press feel like nothing happened, and you’d need to press back again.
Am I tripping here? That’s how androidx.navigation handles start destinations right?
With this in mind, shouldn’t the start destination in reality be the schedule screen, but with a default value of no conference selected. And then that can figure out if there’s a conference selected to show that one, or if the destination URL contained a conference so that it uses that one (and saves it in preferences too potentially), or if none of the previous two alternatives are true, to automatically navigate to the conference picking destination?mbonnin
04/09/2023, 7:03 AMWhen nesting graphs, the start destination from each level of nesting—that is, the start destination from each <navigation> element in the hierarchy—is also added to the stack.My understanding was that we don't have 'nested' graphs only one flat navhost. But maybe I'm misreading things there
yschimke
04/09/2023, 7:08 AMSounds like you are over complicating things, given that you can do exactly that -defaultValue = intent.getExtra("yourExtra")
mbonnin
04/09/2023, 9:07 AMsession/$conferenceId/$sessionId
opens the specific session of the specific conference
• conferences
opens the list of conferences
• initialLoading
opens a progress view that loads from shared preferences and then redirects to sessions/$conferenceId
when a user presses the Back button from a deep link destination, they navigate back up the navigation stack just as though they entered your app from its entry pointBut then yea if the start destination is added in our case and the stack is of size 2 then it's a problem
yschimke
04/09/2023, 9:31 AMmbonnin
04/09/2023, 9:32 AMyschimke
04/09/2023, 9:32 AMStylianos Gakis
04/09/2023, 10:05 AMyschimke
04/09/2023, 10:11 AMStylianos Gakis
04/10/2023, 7:40 PM"<confetti://confetti/sessions/{conference}>"
and we start the app using a string like <confetti://confetti/sessions/kotlinconf2023>
, I did not find a way to extract this “kotlinconf2023" outside of the NavHost so that I can pass it in the defaultParameter
. I see in your PR you’ve also left it as a //todo
Doing intent.getStringExtra("conference")
seems to be null. In fact the entire intent.extras seems to be null (at least inside the onCreate where I was trying to read it) I feel like there’s something I am missing here, haven’t really worked with deep links before.
Instead doing intent.data
gives me back “confetti://confetti/sessions/kotlinconf2023" but aside from doing intent.data?.pathSegments
on it, and trying to figure out what the result was by taking the last one, I don’t know how else I’d get it. It seems like you can’t get it by the id it had, since it’s already decoded to “kotlinconf2023” in this case.
Quite confusing overall tbh 😅 I agree that having a home destination which also expects a variable is quite confusing. If the home destination was something more “static” the nav library handles it in such an easier wayyschimke
04/10/2023, 9:09 PMStylianos Gakis
04/10/2023, 9:32 PMI think it requires parsing the uriSo that’d mean literally doing this yourself then right? I guess if we know the url and that it’s always the last path segment it’s simple enough. As long as that’s a normal thing to do.
yschimke
04/10/2023, 9:34 PMStylianos Gakis
04/10/2023, 9:41 PMyschimke
04/10/2023, 9:56 PMStylianos Gakis
04/10/2023, 10:03 PM