You're Collecting Your Flows Wrong In Compose | THIS Is Why

  Рет қаралды 27,629

Philipp Lackner

Philipp Lackner

Жыл бұрын

In this video you'll learn how to correctly collect flows in jetpack compose with the new stable collectAsStateWithLifecycle function.
⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:
pl-coding.com/premium-courses...
Get my FREE PDF about 20 things you should never do in Jetpack Compose:
pl-coding.com/jetpack-compose...
💻 Let me be your mentor and become an industry-ready Android developer in 10 weeks:
pl-coding.com/drop-table-ment...
Subscribe to my FREE newsletter for regular Android, Kotlin & Architecture advice!
pl-coding.com/newsletter
Join this channel to get access to perks:
/ @philipplackner
Join my Discord server:
/ discord
Regular programming advice on my Instagram page: / _philipplackner_
Checkout my GitHub: github.com/philipplackner
You like my free content? Here you can buy me a coffee:
www.buymeacoffee.com/philippl...

Пікірлер: 49
@style966
@style966 Жыл бұрын
Hey Philipp, thank you for such a nice explaination. Btw, you are repeating yourself at 6:22 . I am guessing there is editing issue.
@dpearson
@dpearson Жыл бұрын
Love hearing the explanation and seeing the examples. Great work. Thanks Phillip!
@devgabriel6898
@devgabriel6898 Жыл бұрын
Thanks Philip, you re my absolute Android mentor! Always waiting for your videos to come out. When i found a USD job (i have one, but in local currency which is garbage) i will definitely buy some of your courses
@mircodev
@mircodev Жыл бұрын
Hey Philipp, many thanks for the clear explanation.
@ngomdecadetkamdaou3464
@ngomdecadetkamdaou3464 Жыл бұрын
Interesting, I read the documentation but didn't understand it like that. Now with your video, it's very clear.
@king_vidda
@king_vidda Жыл бұрын
Them videos coming in 🔥🔥🔥 and educative... Thanks Philipp ❤️
@rizwansworld
@rizwansworld 9 күн бұрын
Thanks man. Really helpful.
@John-qt6qk
@John-qt6qk 6 ай бұрын
Great explanation with some use case examples thanks Phillip
@tikayz
@tikayz Жыл бұрын
Thanks Phillip
@BrunoMilhan
@BrunoMilhan Жыл бұрын
Thanks Philipp! And about implement a collector inside of a viewModel? I'm using a mutableStateList to fill my LazyColumn, so my approach was start a collector in vm and update my stateList from that.
@johnshepard1267
@johnshepard1267 Жыл бұрын
Great video! Please make more videos on flows and stateFlow and different best practises!
@ChrisAthanas
@ChrisAthanas Жыл бұрын
He has videos on this already
@osisuper98
@osisuper98 Жыл бұрын
Much love bro!
@olgaderyabina7519
@olgaderyabina7519 9 ай бұрын
Thanks very much, that's really helpful. I am currently doing some r&d with Kotlin multiplatform mobile and looking into sharing across both Android and iOS all the layers including the views (composables) and view models. In general, everything works great, but I still don't have an opinion on how to deal with the lifecycle thing you mentioned at the end of the video (definitely will need to spend more time on the iOS-side investigation). So far lifecycle-related events is the only phenomenon that requires so much attention in the multiplatform project 🙂
@zohaibraza1365
@zohaibraza1365 Жыл бұрын
Nice Explanation 👍🏻
@harshv.tewari6869
@harshv.tewari6869 Жыл бұрын
Thanks for sharing. It was helpful ^_^
@samdroid37
@samdroid37 Жыл бұрын
you are a blessing
@bofu9662
@bofu9662 Жыл бұрын
Nice video!!!
@il_benza
@il_benza Жыл бұрын
Can you explain in a video, difference between using MutableState and MutableStateFlow?
@mesutemrecelenk5447
@mesutemrecelenk5447 Жыл бұрын
Thanks Phlipp. Must we use to collect variables (for example list data) that in our state data class with collectAsStateWithLifecycle?
@chndraja
@chndraja Жыл бұрын
Hi Philipp Lackner, please make a video on how to handle the flow values emitted from Room Database. Should i use asStateFlow, or StateIn while collecting the flows from room database? Your previous video on flow mistake helped me to resolve a issue. thanks for the help.
@osisuper98
@osisuper98 Жыл бұрын
You should use “StateIn” operator since you will be having cold flows from ROOM and not hot flows (MutableStateFlows or MutableSharedFlows). If you then need to use the result with other flows (say hot flows declared in your viewmodel), you can combine all with the “combine” operator.
@federicocreti4699
@federicocreti4699 5 ай бұрын
Thank you Phillip..as always very nice video. I have a big doubt: figure we are handling our UI state with a class. So inside the class for example we have a list of something. The list is retrieved through a repository and figure it's come from room. Since we are handling all through a state class what we do is to collect the list from the view model and when we receive a new list we will update the state UI. The UI is collecting our state and not directly the list (which as we said is collected in the VM). Now even if the app goes in background the VM still collects update from repository. How do we handle this?
@ramazanmutlu9911
@ramazanmutlu9911 Жыл бұрын
Hey Philip, first of all thank you for these perfect-explained videos. But I think those both have different use cases so we can't say that someone using it wrong.
@PhilippLackner
@PhilippLackner Жыл бұрын
For Android it's certainly wrong. In which case would you not want to collect your flows with collectAsStateWithLifecycle?
@VinayKumar-t6m5s
@VinayKumar-t6m5s 10 күн бұрын
How to recompose the screen when data saved to shared preference?.
@stijndcl
@stijndcl Жыл бұрын
At the end you mention that the lifecycles only exist on Android, and the regular version are for desktop. Wouldn't that mean that this issue is still present on desktop? What would be the fix there?
@LightDante
@LightDante 11 ай бұрын
Is there a better way than 5 seconds which is hardcode?
@dimii1_
@dimii1_ Жыл бұрын
Hey Philipp what is the theme you are using? How is it called?
@wetfloo
@wetfloo Жыл бұрын
it's xcode theme
@iftak01
@iftak01 2 ай бұрын
Does this Apply to STATEFLOWS too!??
@thencode8403
@thencode8403 Жыл бұрын
❤❤
@Shakesbeer1
@Shakesbeer1 Жыл бұрын
I would like to try launcher that you use at your device. Could you please share?
@PhilippLackner
@PhilippLackner Жыл бұрын
I don't use a launcher
@Shakesbeer1
@Shakesbeer1 Жыл бұрын
@@PhilippLackner But icons have a particular style. Theme?
@arfinhosain4969
@arfinhosain4969 Жыл бұрын
oh, i just saw normal philipp for a second. 😁😁😁😁
@fishman8tw
@fishman8tw Жыл бұрын
me 2
@stephanhaller
@stephanhaller Жыл бұрын
1st
@mr.chouhan_07
@mr.chouhan_07 Жыл бұрын
hey philipp I've used your coroutines with retrofit tutorial but I am facing a problem. the problem is that when we get our api response from enqueue we also get response in run and logcat which makes it easy to understand when If we are using lifecycleScope then nothing is showing response in run and logcat please help me (this is your tutorial link: kzfaq.info/get/bejne/qpyDpM9kvLOlnp8.html )
@ChrisAthanas
@ChrisAthanas Жыл бұрын
Strange edits at 6 minute mark
@PhilippLackner
@PhilippLackner Жыл бұрын
Oops sorry I oversaw that
@andreass7012
@andreass7012 Жыл бұрын
Why don`t you use new UI in studio?
@aldredo5543
@aldredo5543 Жыл бұрын
Thanks 🔥
@stefanusayudha1853
@stefanusayudha1853 Жыл бұрын
tobe honest this api is so ugly.. though it is working.. i feel it so wrong.. i believe the problem occurs because Garbage collector method is not suitable for declarative programming.. Declarative programming need different methods to be optimized.. as the way it's nature should be.. delete memory once. scope is ends.. thats it.. everybody happy.. Im starting to think that we have a very big problem here.. don't get me wrong I'm just kinda frustrated, and even though it is working, i didn't feel it's helpful... i hope they get rid of this method soon, and back to nature.. it should be simple, thats the idea of why compose is been made
@nickvillareallycool5228
@nickvillareallycool5228 Жыл бұрын
I don't understand why you use StateFlow instead of just State and using the .value property directly. Is there a reason?
@PhilippLackner
@PhilippLackner Жыл бұрын
StateFlow makes it easy to add reactivity to your state
3 Clean Code Hacks I Bet You Didn't Know (Kotlin & Android)
12:30
Philipp Lackner
Рет қаралды 26 М.
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 8 МЛН
derivedStateOf VS. remember(key) - THIS is Really the Difference 🤯
14:46
Collecting flows in a lifecycle-aware manner
6:35
Android Developers
Рет қаралды 17 М.
Should You Use Compose State or StateFlow in Your ViewModels?
13:59
Philipp Lackner
Рет қаралды 74 М.
5 Fatal Coroutine Mistakes Nobody Tells You About
18:15
Philipp Lackner
Рет қаралды 86 М.
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 36 М.
The Top 3 State Management Mistakes On Android
14:30
Philipp Lackner
Рет қаралды 23 М.
Opensource, Uncensored, Unbothered. - Flux.1 Image Gen
18:59
MattVidPro AI
Рет қаралды 2,6 М.
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 8 МЛН