Has anyone faced any issue with destinations v2 I ...
# compose-destinations
s
Has anyone faced any issue with destinations v2 I have multiple NavHostGraph (previously was using single default RootGraph And now i get this issue.
java.lang.RuntimeException: Context was requested, but it is not present
r
Hi! Do you also have multiple DestinationsNavHost calls?
s
Not in the same composable or screen if thats what you mean. P.S I love your work Rafael.
r
(Thanks!) I don’t mean in the same screen, I mean generally.
s
Yes I do I have deconstructed my Application into multiple flows and was thinking for each flow ill use its own NavHostGraph without a parent and connect these separate graphs using normal activity calls. Am i doing anything wrong here?
Each flow is contained in a separate activity. which helps me in killing everything related to that flow
r
It’s hard to know. Generally speaking, I believe having a single top level NavHost call is better. If you have multiple, you have to understand the each has its own NavController, and each NavController can only navigate within its own destinations / graphs
If you use multiple Activities, it should be easier to manage multiple NavHosts. But again, you won’t be able to navigate from feature A to a inner screen of feature B. Only to feature B activity
s
That is understood, that's why i implemented in such a structure so that i can have separation of concerns between different graphs. I'm trying to have as flat a hierarchy possible of navs
Yes, i understand i wont be able to and that is how i want to keep things as well.
r
Ok sounds good then 👌
Im not sure what could be causing the missing nav argument then (I assume from the log you posted that’s what it is)
s
Oh wait, is it absolutely required to pass the destinationNavigator?
in the composable?
r
No.
Can you post the stack trace of the crash?
It would seem that one of your destinations is receiving a “Context”. Can you identity this parameter? Is it not a nav argument?
Is it Android context?
s
Rookie mistake, i've figured it out rafael. Sorry to waste your time. I'm still getting my head around the entire compose navigation structure. I basically refactored my code into separate files and there was a top level context that was being passed and when i refactored i didn't check properly the parameters of each composable and there was a parameter of context. Which obviously i hadn't and shouldn't provide in the dependencyContainerBuilder
That's what was breaking.
r
Perfect 👍 glad I helped in some way
💯 1
s
the moment you mentioned navargs it clicked Thankss
r
I could make the exception message a bit more helpful 😛
just by saying "not present in dependency container" or similar, it could have saved you some time
1
s
Just to get ahead What do you think of the nav structure i mentioned? Will it hold?
r
The only concern that comes to mind is with deep links.
I'm not sure how the app will behave to those. Maybe you'd have to redirect them to specific activities manually? 🤔
not sure...
s
Better messaging always helps. I'm very impressed by the quality of library and the support. Phillip also did a great job in explaining. But otherwise the documentation is well written too Let me know if i can help in any way. Would love to be involved. I was a opponent of navigation itself before compose, i only moved to navigation because of destinations in both compose and xml
I don't have many use cases for deep links but will look into it wherever it comes into place, Maybe the activity will have to handle the deeplink and then forward it to screens, i'll have to look into it.
r
Everything should be doable 👍
🙌 1
s
Just a thought, What if to control the activities as mentioned will be my entry points for each graph is annotated with activitydestinations? Then the deeplink issue shouldnt come too right?
The idea of going with multiple activities was to have them self contained
r
Hmm, then I don’t know tbh. Since you still have another NavHost in the middle. Not sure if it will be smart enough
What about it makes it more self contained in your view? The alternative being that each feature would expose a NavGraph that gets included in a main graph in the main DestinationsNavHost?
s
Thats the idea, that each feature would be exposed to the mainappnavgraph Each features' entry point would be an activity
r
Yes, but then each activity has its own NavHost, right? That’s what I’m saying. If you forget the activities and the additional NavHosts, each module provides a nested NavGraph and there’s a single main NavHost graph that contains all features’ graphs.
Why is that less “self contained”?
Im not suggesting it’s a wrong idea btw, im just trying to understand it 🙂
s
You are right, its back to the same idea of single activity arch, without the NavHost graph actually being a single activity.
r
Once you go single activity, you can’t go back 😜 I just find it way easier to manage
s
I'm trying so hard to not go single activity. But also i'm not finding many cases that cant be done in single activty arch 💀💀💀 It's like im gatekeeping myself lmao
I guess it's just a behaviour that is set in. I always think of activities as a hard death of anything connected to it and helps me think that everything related to it as cleared off and died Rest screens in this case feel very soft deaths, and doesnt give me assurance that everything has been cleaned
Maybe i have to look deeper into creation and death of screens and how can it be still done in singleActivityArch
Also what helps me is that the Viewmodels that i attach to an activity which is held in reference for all its subsequent screens in the same flow i know it can be done similarly for the single acitivity arch too but like in acitivty i know that the activity will clear everything and the viewmodel will do its job too
r
You can tie VMs to nested graphs to achieve the same behaviour. If you want to clear everything from a “feature” you can pop the nested graph entry from the back stack. As long as you don’t tie things specific to features to the Activity (I never had such need) then it’s easy and you still know that everything is cleared. That said, I am not against what you’re suggesting either, I just personally like it better this way 🙂
s
i understand rafael. Thanks a lot for your input.
r
Sorry I made a mistake, let me fix it 😅
s
But still i understood what you are trying to put forward
👍 1
r
Done
🙌 1