Side Effects & Effect Handlers - Android Jetpack Compose - Part 10

  Рет қаралды 24,810

Philipp Lackner

Philipp Lackner

3 жыл бұрын

In this video you will learn about side effects and effect handlers in Jetpack compose.
⭐ 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...
💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
elopage.com/s/philipplackner/...
Regular Android tutorials on my Instagram: / _philipplackner_
Checkout my GitHub: github.com/philipplackner

Пікірлер: 46
@PhilippLackner
@PhilippLackner 3 жыл бұрын
I re-uploaded this video because the previous video had a messed up quality (only 480p). This is now in 4K again as usual
@otoS97
@otoS97 2 жыл бұрын
Now I don't understand side effects in 4K
@nilanjanmukhopadhyay8369
@nilanjanmukhopadhyay8369 2 жыл бұрын
In case you are wondering how LaunchedState does that, There are two cases where a LaunchedEffect can get canceled. 1. The key of the LaunchedEffect changed 2. The composable launched inside the "LaunchedEffect" isn't in UI the tree anymore after a recomposition Reason 2 applies in this case. When the `counter` reaches some value that is divisible by 5 the snackbar, inside the "LaunchedEffect" gets fired and added to the UI tree. On the next click, the value of the counter will be changed to something that is not divisible by 5. For this state change, a recomposition will immediately take place. But this time "counter" wouldn't satisfy the "if" condition. And the "snackbar" won't be added to the UI tree this time. Previously launched `LaunchedState" would notice that and cancel the "snackbar" anymore. To summarise, 1. counter < 5, no snackbar in the UI tree 2. counter == 5 -> recomposition happens -> snackbar is fired and added in the UI tree (LaunchedState would observe for any recomposition) 3. counter == 6 -> recomposition happens -> snackbar isn't in the UI tree anymore because of the "if" condition -> LaunchedState observes this and cancels the previously launched snackbar
@st4849
@st4849 2 жыл бұрын
This I understand, thank you. I still don't get why he added key1=... It didn't make any difference, could have added key1=true even. No?
@ZaidZakir
@ZaidZakir 3 жыл бұрын
this video was a bit hard to understand haha, so had to rewatch it 3 times :D
@calinpuiu2344
@calinpuiu2344 2 жыл бұрын
Thumb up! You are a mine of knowledge. For five days I struggle between your videos to find a manageable solution to validate a login form with a Retrofit call. I don't know if the LaunchedEffect presented in this video is the perfect solution, but seems to work for me. Thanks, and keep up the good work!
@ConfusedNDazed
@ConfusedNDazed 3 жыл бұрын
Having come from 1 year of SwiftUI dev, I find this quite verbose and hard to follow. Everything up to this video was pretty easy to follow. Hopefully watching the Pokédex videos will make things clearer
@ambermalandkar1138
@ambermalandkar1138 3 жыл бұрын
man love your videos, thx!!!
@ashutoshsingh4905
@ashutoshsingh4905 3 жыл бұрын
I dont know why but when I watch your video It feels good and I learn a lot from this . Thanks for such good video. Love from INDIA
@SpaceTimeBeing_
@SpaceTimeBeing_ 3 жыл бұрын
Oof this one is the most alien to me, the rest were easy
@thiagosouza8931
@thiagosouza8931 3 жыл бұрын
😂
@lewekandi784
@lewekandi784 2 жыл бұрын
I Philip thank you very much for programing the application data.
@amineayachi335
@amineayachi335 2 жыл бұрын
thanks again
@ARIHANTJAIN27
@ARIHANTJAIN27 2 жыл бұрын
You should explain guideline and barrier in details for constraint layout using compose
@fahadalotaibi6340
@fahadalotaibi6340 3 жыл бұрын
thanks
@theonlyarjun
@theonlyarjun 3 жыл бұрын
Which side effect can I use to detect the first time the compose composed, I just want to trigger some action for the first time and not every time the compose recomposes
@user-bj9dl4zw9c
@user-bj9dl4zw9c 3 жыл бұрын
Hi Philipp! Thank you for your teaching! Maybe you could answer my question? Do you know how to process the response from API in the html format?
@shivamsethi3829
@shivamsethi3829 3 жыл бұрын
React use Effect android version, I love it
@thomaswaldorf2829
@thomaswaldorf2829 3 жыл бұрын
I was thinking the same thing :D useEffect with cleanup
@AIejandroide
@AIejandroide 2 жыл бұрын
10:32 I have a question, you set the scaffold.snackbarHostState as the key of the launchEffect, but when you click on the button you dont actually update that value, you just update the counter, the code won't even enter the if where you set the launchEffect. So why is the coroutine that shows the snackbar cancelled when you inmediately click the button again to change the counter if the counter is not the key ?
@Mahi-hn8tr
@Mahi-hn8tr 4 ай бұрын
Bro.. This is out of the playlist - jetpack compose. Please check
@Berk45632
@Berk45632 3 жыл бұрын
I didn't get this.. how is the coroutine getting cancelled in LaunchedEffect? Can you explain again?
@PhilippLackner
@PhilippLackner 3 жыл бұрын
It gets canceled whenever the key you pass changes, so in this case whenever scaffold state changes
@thebigboi5357
@thebigboi5357 3 жыл бұрын
@@PhilippLackner And the scaffold state changes because the counter changes?
@nilanjanmukhopadhyay8369
@nilanjanmukhopadhyay8369 2 жыл бұрын
There are two cases where a LaunchedEffect can get canceled. 1. The key of the LaunchedEffect changed 2. The composable launched inside the "LaunchedEffect" isn't in UI the tree anymore after a recomposition Reason 2 applies in this case. When the `counter` reaches some value that is divisible by 5 the snackbar, inside the "LaunchedEffect" gets fired and added to the UI tree. On the next click, the value of the counter will be changed to something that is not divisible by 5. For this state change, a recomposition will immediately take place. But this time "counter" wouldn't satisfy the "if" condition. And the "snackbar" won't be added to the UI tree this time. Previously launched `LaunchedState" would notice that and cancel the "snackbar" anymore. To summarise, 1. counter < 5, no snackbar in the UI tree 2. counter == 5 -> recomposition happens -> snackbar is fired and added in the UI tree (LaunchedState would observe for any recomposition) 3. counter == 6 -> recomposition happens -> snackbar isn't in the UI tree anymore because of the "if" condition -> LaunchedState observes this and cancels the previously launched snackbar
@AlgeriaHere
@AlgeriaHere 2 жыл бұрын
Hello Guys , I'm actually facing an issue which is related to this video topic , basically i want to fetch data from Rss Feed and i need to connect to a website to fetch the data , i know this is a side effect to execute network operation inside a composable , but what is the alternative for that , Thank you ?
@jimpauloovejera2599
@jimpauloovejera2599 2 жыл бұрын
I am still pretty confused how LaunchedEffect was able to cancel the snackbar
@jimpauloovejera2599
@jimpauloovejera2599 2 жыл бұрын
LaunchedEffect's scope is cancelled once it leaves the composition. For rememberCoroutineScope, the coroutine keeps running because the composable wasn't removed from the tree, hence, snackbar were just queued.
@DennisEspiritu
@DennisEspiritu 2 жыл бұрын
Your previous Compose videos were easy to follow until this 😄
@PhilippLackner
@PhilippLackner 2 жыл бұрын
I know, that's why I recently made a new and better one about effect handlers: kzfaq.info/get/bejne/nd6HlsmrmLyWgXk.html
@federicocreti4699
@federicocreti4699 2 жыл бұрын
Of course I'm missing something but things are unclear. You say you need to do network calls (obviously) but why don't you use view models for this? Then you say if you do a network call inside a compose this call will be triggered everytime the it is recomposed, so I don't understand the effective solution given by SideEffect. You say it run the function just when the component is correctly recomposed, but what does that mean? Isn't the network call done over and over in the same way of not using SideEffect?
@md.rafsanbiswas5321
@md.rafsanbiswas5321 2 жыл бұрын
API is calling when get back to compose screen. Please leave a solution.
@abada-s
@abada-s 2 жыл бұрын
I hope you to show effects practically on emulator , to see some examples
@nickvillareallycool5228
@nickvillareallycool5228 2 жыл бұрын
This would have benefited from examples
@Berk45632
@Berk45632 3 жыл бұрын
This video got me anxious about the side effects from the vaccine I just got. 😰😰
@SpaceTimeBeing_
@SpaceTimeBeing_ 3 жыл бұрын
Side effects for vaccine is just increased 5G coverage
@sergeyplotnikov5031
@sergeyplotnikov5031 2 жыл бұрын
difficult topic
@viveksingh9223
@viveksingh9223 3 жыл бұрын
Is this a re-upload or I am having dejavu.🤔🤔
@PhilippLackner
@PhilippLackner 3 жыл бұрын
no its a re-upload with fixed quality issues :D
@viveksingh9223
@viveksingh9223 3 жыл бұрын
@@PhilippLackner I got confused because I had finished watching the previous upload just five minutes ago.
@thomaswaldorf2829
@thomaswaldorf2829 3 жыл бұрын
Most of this feels like programming React with functional components.
@pradeepkumarreddykondreddy7048
@pradeepkumarreddykondreddy7048 2 жыл бұрын
Could not understand anything
@yonghunchoi8944
@yonghunchoi8944 2 жыл бұрын
겁나 어렵네 하 ㅠ
@tommy9x
@tommy9x 2 жыл бұрын
From lesson 9 to 10 Not understand
@chenchiaho
@chenchiaho 2 жыл бұрын
dont quite understand this
@richiekosher6218
@richiekosher6218 2 жыл бұрын
honestly why do you do half the video without really showing whats happening? kinda feels like being in uni instead of watching a hands-on tutorial on youtube
Should You Use SharedFlow?
9:30
Philipp Lackner
Рет қаралды 23 М.
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 25 МЛН
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,7 МЛН
Llegó al techo 😱
00:37
Juan De Dios Pantoja
Рет қаралды 59 МЛН
Should You Use Compose State or StateFlow in Your ViewModels?
13:59
Philipp Lackner
Рет қаралды 74 М.
Full guide to Jetpack Compose Side Effects
25:44
Land of coding
Рет қаралды 1,7 М.
Full Guide to Jetpack Compose Animations - Android Studio Tutorial
28:23
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 25 МЛН