Kotlin StateFlow Tutorial | StateFlow vs LiveData vs SharedFlow | CheezyCode - Hindi
HTML-код
- Опубликовано: 11 сен 2024
- Kotlin Flow Tutorial - Learn what is stateflow? Learn the difference between shared flow, stateflow, and livedata. Learn what is actual difference between shared flow and state flow with example. State Flow maintains the last value or the latest value emitted in the flow. State Flow is also a shared flow but with single buffer to keep the conflated values in the flow.
LiveData transformation are executed on main thread whereas in StateFlow you have flowOn operator to execute the transformation on different dispatchers. LiveData is commonly used in Repository although it requires Lifecycle object to work. For these scenarios, it is recommended to use StateFlow. Learn what is Mutable State Flow and how it is different from Shared Flow and LiveData. Learn all these with example in Kotlin Flows in Hindi.
Topics covered -
1. Shared Flow - Hot Stream Examples
2. Shared Flow vs State Flow
3. What is State Flow?
4. StateFlow vs LiveData
4. Complete Example of StateFlow & MutableStateFlow
Kotlin Flows Playlist -
• Kotlin Flows Tutorials
Jetpack Paging Tutorial -
• Android Paging 3 | Jet...
Complete Dependency Injection Playlist Link -
• Dagger 2 - Dependency ...
Complete Android Architecture Components Playlist -
• Android Architecture C...
Beginner series in Android Playlist (Hindi) -
• Android Tutorials Step...
Kotlin Beginners Tutorial Series -
• Kotlin Beginner Tutori...
For more info - visit the below link
www.cheezycode.com
We are social. Follow us at -
Facebook - / cheezycode
Twitter - / cheezycode
Instagram - / cheezycode
I just completed this Flows series. Thank you CheezyCode for providing such straightforward and clear explanation videos and tutorials. I am an Android Developer and whenever I need to learn something new, I visit CheezyCode first. You have helped me a lot in my Android development journey. Thank you, again.
Just completed whole series. Great tutorial. Thank you for such clear and concise explanations.
You're very welcome!
Thank you for making this playlist
You've made flow simple 😊
Great tutorial and channel I had a career break of 6yr and while learning kotlin corutine and flows amazing explanation help me a lot thank you so much 🙏
Nice instructor.
Hr topic clarity k sth smjhaya hai.
Thanks man. Really well explained!
beautiful series of 6 vedios short, simple & crystal clear, Thnks sir🙏
Sir Maja hi aa gaya you are really confidence booster 😍😍😍😍😍,Sir aur videos bachi hai is playlist me ? I am preparing for interview in top MNC is this playlist enough ? and Sir one more thing aap kaha job karte ho ?
thank you...interview ke liye I guess kaafi hai ...bas MVVM mei integrate aur karlo...uspe video dalni hai thoda samay lenge...but jaldi he upload karta hu....ek US based company hai...Noida mei dev center....
@@CheezyCode Ok Sir thanks for the guidance 🥰
Explained in very simple terms. Great !!! Keep it up !
Excellent, Outstanding. You made Flow simple!!
I appreciate your clear communication. Thanks!
Best, simple clear, Thank you for such quality contents
Simple and sweet explanation.... with no bakhwas like angragi videos.😄
Brilliant videos. Thank you so much
Simple and clear . Thank u ☺️
Sir, plz make a video on Unit testing Mockito, JUnit, Roboelectric
Best explanation ever
Thanks for the video , Its really helpfull , I just wanted to know is there any videos coming on these flows ??? i means is der any major concepts remaining in this flows section ??? coz i am preparing for interview on ur video basis . . . major topics
Majorly yehi hoga...baaki operators he h...uski koi limit nahi...concepts isse deep mei nahi puchne chaiye interview mei
Thanks for this series :)
Explanation at the easiest level! However, I have a question here.
When explaining difference between LiveData and StateFlow, you said that Livedata is lifecycle aware but if we are collecting a flow inside a coroutine scope then does that means StateFlow is also lifecycle aware, as coroutine also has a lifecycle scope?
Not directly aware but linked via coroutine scope
Tussi great ho aap🙇
Thank you 😃
Superb sir 👌 👏
Mind blowing sir 🔥🔥🔥❤️❤️❤️
Thank you 😃
nice content sir
Thank you so much for the lovely tutorials. You explain very nicely.
I have a question If we use SharedFlow with replay 1 then Isn't it the same as StateFlow?
State Flow will provide you only current state. But let's say as you subscribe, emitter starts emitting...you will be getting 2 values at the same time(one because of replay and other one will be currently emitted value)...but with state Flow you will only get 1 value and that will be the latest one no matter what.
Semantic difference hai...stateflow means flow having state
Hope this helps 🤘🏻
@@CheezyCode okey it means sharedFlow is not giving us latest value where as stateFlow is giving latest value right ?
very nice and well explained...
Thanks Anup
Good explanation of flow...thank you for this smooth understandable video....can you make a video for Android HAL (camera, audio, media player,BLe etc) concept please.
Thanks...will see
@@CheezyCode thanks you 😊
was this last video of flows series?
Inhone number nai daala 1 2 karke mera v bhatkao ho gaya tha 😅
Playlist h 😂 jitne hai yehi h....
@@CheezyCode ok sir
Bhai Shared flow to samajh main aagaya and State flow bhi but State Flow ka kuch real world example miljata to samajhne main asani hoti aaur, jaise aapne shared flow ka example deke samjhaya cinema hall wala.. waisa kuch real world scenario main or else programming main kab use kare shared flow wo jan.na hai
Jahan pe livedata use kar rahe ho...waha pe stateflow se replace kardo...notes wali app mei replace karke dikhata hu jaldi he
@@CheezyCode Sahi hai bhai just post kiya aapne, dekh raha hun StateFlow vs LiveData. Notes app
Timimg at 5:38, shows that item ("5") collected before emitting why this output?
The difference in last 10:21 , isn't it between flow and live data rather than state flow and live data??
State Flow is a flow?
@@CheezyCode yes, stateFlow is a flow. I am saying you said and labelled the difference as 'LIVEDATA VS STATEFLOW' when it doesn't contain any particular property of stateFlow, all difference are of flow. Label ' livedata vs flow' is more accurate imo
Yes... generally people use stateflow to replace livedata that is why I have written this.
@@CheezyCode ok understood.
Nice video btw. All of your videos are really helpful. Thank you very much for creating.
Very good
Thanks 👍
Thanks Sir
Welcome ✌
hello sir, what is Rxjava??
i m confused for Rxkava n liveData both are same ya different??
RxJava - duniya hai poori..
LiveData - uska minuscule version hai...RxJava ka ek concept hai uska chota sa implementation hai....
बहुत बढ़िया, साला कन्फ्यूज कर रखा था
If I need to return non-stream kind of data like api response of any profile, so should I use flow or simple suspend function?
i guess simple suspend function
/* different topics */
Sir , I have some data which I want to use in my entire app but dont want to use bundle or put extra method to send data to different activities or fragment
Is there any way to do that please tell me
you can keep them in application object - but risky hoga toh keep it as singleton...make sure you don't pollute the global object...warna soch ban jaati hai baad mei ki sab kuch global pe he rakhdo....jetpack data store can also be used , create a wrapper around it to get the data from that...single place of getting and storing the object.
@@CheezyCode sir shared preference nahi use kar sakte kya??
Personal note: stateFlow vs livedata
At 6:35 what if we used replay in sharedflow will it collect since emit has stopped after 6 ms.
yes that's why it is a special type of Shared Flow...isme ek concept aur hai - Conflation ka - i.e. it will keep the latest value
Good question hai waise....that means you understood the concepts well... 🤘
@@CheezyCode Also coroutineScope does not have lifecycle so what happens if app is closed, will it still work or stop.
Scopes hote hai coroutines ke...like viewmodel scope and lifecycle Scope... activity destroy hogi toh lifecycle Scope bhi destroy hojayega...uske andar ka flow bhi....app close pe activity destroy nahi hui hogi toh maintain hona chaiye
@@CheezyCode let me rephrase it, what is scope of "CoroutineScope(...).launch " this piece of code . I want to know scope of this. The lifecycle,global scopes I understood but scope of code in quotation I do not know
good video. but i want help in socket tcp client server so can you help me here
?
@@CheezyCode how to send data from our app to laptop?
Via bluetooth karlo..socket tak mat pahocho...
@@CheezyCode haa but wapas data socket server se lenaa bhi hai naa like TCP client or TCP server dono use krnaa hai.ye chij Bluetooth me kese hogaa
Thanku Sir....Awesome....
🤘