Navigation In Multi-Module Android Apps - Why You're Doing It Wrong!

  Рет қаралды 13,507

Philipp Lackner

Philipp Lackner

Күн бұрын

Пікірлер: 50
@hovseparakelyan7655
@hovseparakelyan7655 2 ай бұрын
Great video! I noticed that when working with deeply nested composable functions, managing navigation through lambdas can become cumbersome. To address this, I implemented a modular Navigator pattern for each feature module. Here's how it works: 1. Each feature module has its own Navigator (injected via DI) that emits navigation actions using a Channel or StateFlow. 2. The feature module's root composable listens to the navigator and communicates with the main app (e.g., MainActivity) via a callback. 3. Nested composables can directly trigger navigation events (e.g., navigator.event(NavAction.Back)), avoiding the need to pass lambdas all the way back to the root. The key benefit is that this pattern allows me to keep my feature modules completely independent of the app's NavController, as the Navigator is part of the submodule itself. This makes the modules reusable, decoupled, and easy to test. Let me know what you think, and thanks for sharing your insights in this video!
@StreetsOfBoston
@StreetsOfBoston 2 ай бұрын
Makes absolute sense :) If you have separate (and uncoupled!) features, using Dependency Inversion for navigation (and any other (shared) dependencies they may rely on) is the way to go!
@AndrewDChristie
@AndrewDChristie 2 ай бұрын
Thanks!
@yashtalreja1946
@yashtalreja1946 2 ай бұрын
sir currently i am watching your jetpack compose playlist and i feel its very structural and very understanding but i have one request for you is that i want you to create a playlist on creating projects like E-commerce app ,Food ordering app , Cab booking etc by using kotlin and jetpack compose ,Firebase which will help us all in learning android app developer in efficient way and project based learning
@fabiovokrri517
@fabiovokrri517 2 ай бұрын
That's exactly how the documentation tells you to develop navigation
@RanbirSingh-dl9co
@RanbirSingh-dl9co 2 ай бұрын
This approach works well for two to three screens per module, but as the number of screens grows, Compose Navigation might not support maintainable code. The use of lambda functions increases, and writing all the screens in the home screen will cause issues. You might consider creating feature modules for navigation control extensions and passing lambdas to those, or handling everything in the main screen. Either way, it can lead to complications. I recommend using Voyager, where you can access a local Navigator object that is independent of the main screen or any module
2 ай бұрын
Thanks to share this point of view. It makes absolute sense.
@ngapps
@ngapps 2 ай бұрын
The same as shown in Now in Android google sample app
@warTag68
@warTag68 2 ай бұрын
Golden content as always!
@jakubmyka1240
@jakubmyka1240 2 ай бұрын
What's your Android Studio theme? It is really nice, is it possible to download it somewhere?
@unknownBoy85lover
@unknownBoy85lover 2 ай бұрын
A worthy video thank you sir ❤
@amalhanaja
@amalhanaja 2 ай бұрын
wdyt if we inject the composable navgraph into a set and using composition local to provide navigation controller?
@Ceisluck
@Ceisluck 2 ай бұрын
what if feature A or B have more than 1 screen, is a overkill to emulate navcontroller, then the options left is to pass down the naController or make a navhost inside feature A or B, wich is BS in a way to see it. But I am ok with what google is recommending in the nowInAndroid sample app
@ajailani4
@ajailani4 2 ай бұрын
I think so. What if the screens are going to grow to hundreds and the modules are dozens? It's kinda hard and takes so much effort to stitch them all in an app module. Looks like a boilerplate too. Or does anyone have a proper solution for that?
@user-rz1hv
@user-rz1hv 22 күн бұрын
@@ajailani4 that's google for ya, they overuse best practices "mechanism" (as a connection with android devs) by pushing literal workarounds. That's why their best practices are shit.
@grossadmiralthrawn8769
@grossadmiralthrawn8769 2 ай бұрын
Does anyone know an Android library for the Matrix protocol.
@ShivaPrasad-hm5lk
@ShivaPrasad-hm5lk 2 ай бұрын
I am making an app now using jetpack compose in which I have used single activity and then in each composable I have one or more apo calls called in coroutines foe sthis mean I am not doing a lot of work on main thread?
@mikejawoski5904
@mikejawoski5904 2 ай бұрын
Is it possible to do shared element transition with multi module?
@PhilippLackner
@PhilippLackner 2 ай бұрын
@@mikejawoski5904 of course
@grossadmiralthrawn8769
@grossadmiralthrawn8769 2 ай бұрын
Interesting and good video.
@shreyassathya374
@shreyassathya374 2 ай бұрын
Great informative video on multi module, Is it possible to please make a video on Event Bus, and use case with a sample app, Thanks in advance.
@hackmedia7755
@hackmedia7755 2 ай бұрын
why not use reflection to autogenerate a route by the class name? wouldn't need to repeat so much code.
@Tomas-g2j4f
@Tomas-g2j4f 2 ай бұрын
you should have feature level navigation files to make the navhost more readable this approach won't work if you have 50 screens
@osisuper98
@osisuper98 7 күн бұрын
Won't that lead to coupling the navController to the feature modules?
@ajaygupta3160
@ajaygupta3160 29 күн бұрын
Hello Sir, I’m an aspiring Android developer working on a multi-module Jetpack Compose stopwatch app. I’m using a foreground service to manage stopwatch logic and display a persistent notification. However, the app gets killed by Android after a few minutes when I put running stopwatch in the background, causing the stopwatch to stop prematurely. Could you please suggest a possible solution to resolve this issue? please help. Please help.
@TheFlexath
@TheFlexath 2 ай бұрын
thanks Philipp
@devatrii
@devatrii 28 күн бұрын
What if we've 100 buttons? Should i pass 100 functions?
@osisuper98
@osisuper98 7 күн бұрын
Haven't yet seen an app with hundred buttons or clicks on one single screen. 😂
@devatrii
@devatrii 7 күн бұрын
@osisuper98 what about nesting inside screen?
@tiltedbybox6118
@tiltedbybox6118 2 ай бұрын
9:39 isn't that what you actually deleted? 😅
@sebastianseno9285
@sebastianseno9285 2 ай бұрын
why people still use multi module in jetpack compose ?
@TheMikkelet
@TheMikkelet 2 ай бұрын
multi module is great in theory, but usually end up with giant core module (essentially an app in it self) and a few, small feature modules - too small to get benefit from compiler... mosty multimodule is good for data layer, like remote and/or local that you can use in any app your need
@TheCypriot09
@TheCypriot09 2 ай бұрын
Why have the common-navigation if you need to decouple the modules? the main application shouldn't care about the screens at the first place. it should care about the navigations to a different screen and not the actual screens. right?
@TheCypriot09
@TheCypriot09 2 ай бұрын
Maybe the common-navigation should need to have an interface (for the screens) where each module needs to use ?
@tasnimulhasan7329
@tasnimulhasan7329 2 ай бұрын
Yeah that's the way google recommend 😊
@baadrqaaba9529
@baadrqaaba9529 2 ай бұрын
Thats the point of using MMA
@deviantstudio
@deviantstudio 2 ай бұрын
just pass the interface with module navigation into the module and implement it in the app
@lale5767
@lale5767 2 ай бұрын
FYI philip I personally hate these kind of titles 'Why you'rr doing it wrong'. How are you aware of what I'm doing? Are you spying on me? 😂 Seriously though, I find it insulting and I'm sure I'm not the only one who finds it tacky.
@Mike-er2ih
@Mike-er2ih 2 ай бұрын
Clickbaitsssss
@PhilippLackner
@PhilippLackner 2 ай бұрын
Thanks for the feedback
@viniciussantosmachado4196
@viniciussantosmachado4196 2 ай бұрын
I personally don't care if the content is good
@lale5767
@lale5767 2 ай бұрын
@@PhilippLackner anytime bro
@lale5767
@lale5767 2 ай бұрын
@@viniciussantosmachado4196 maybe if you're a heavy youtube uaer, it'll wear down on you after a while.
@SiamakAshrafi
@SiamakAshrafi 2 ай бұрын
You should never pass anything complex to your Composable. It should be side effect free and stateless. The ViewModel should do all the work ... so this is obvious :-) Thanks
@PhilippLackner
@PhilippLackner 2 ай бұрын
@@SiamakAshrafi if you're a beginner this is everything but obvious 😄
@SiamakAshrafi
@SiamakAshrafi 2 ай бұрын
@@PhilippLackner Don't tell us we are doing it wrong!!! We have been doing it this way from day one ... 👎🏾
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 57 М.
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Navigation Compose meet Type Safety
16:50
Android Developers
Рет қаралды 19 М.
Why Most People FAIL to Learn Coding
7:56
Sahil & Sarra
Рет қаралды 378 М.
The ONLY Correct Way to Load Initial Data In Your Android App?
12:27
Philipp Lackner
Рет қаралды 44 М.
Every Minute One Person Is Eliminated
34:46
MrBeast
Рет қаралды 47 МЛН
5 Python Libraries You Should Know in 2025!
22:30
Keith Galli
Рет қаралды 89 М.
I've Used Jetpack Compose For 4 Years - Here's the Good and the Bad
16:12
5 Kotlin Coroutine Secrets I Wish I Knew Earlier
24:23
Philipp Lackner
Рет қаралды 24 М.