Coroutine Scopes - Kotlin Coroutines

  Рет қаралды 34,666

Stevdza-San

Stevdza-San

Күн бұрын

🏆 My Online Courses
⭐Discount Coupon: LAUNCH-STEVDZA-SAN
stevdza-san.com
🐱‍👤 Wanna become a member? Join!
/ @stevdzasan
📸 Instagram
/ stevdza_san
Kotlin coroutines provide an API that enables you to write asynchronous code. With Kotlin coroutines, you can define a CoroutineScope, which helps you to manage when your coroutines should run. Each asynchronous operation runs within a particular scope.
Global scope is used to launch top-level coroutines which are operating on the whole application lifetime and are not cancelled prematurely.
A LifecycleScope is defined for each Lifecycle object. Any coroutine launched in this scope is canceled when the Lifecycle is destroyed.
A ViewModelScope is defined for each ViewModel in your app. Any coroutine launched in this scope is automatically canceled if the ViewModel is cleared. Coroutines are useful here for when you have work that needs to be done only if the ViewModel is active. For example, if you are computing some data for a layout, you should scope the work to the ViewModel so that if the ViewModel is cleared, the work is canceled automatically to avoid consuming resources.
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
Other videos:
The Basics - • The Basics - Kotlin Co...
Jobs & Cancellation - • Jobs and Cancellation ...
runBlocking - • runBlocking - Kotlin C...
withContext - • withContext() - Kotlin...
🕒Timestamps:
0:00 - Introduction
3:00 - Create Coroutine Scope
7:50 - GlobalScope
10:47 - lifecycleScope & viewModelScope

Пікірлер: 34
@duncanmoiyo6069
@duncanmoiyo6069 9 ай бұрын
You've significantly simplified the comprehension of coroutine scopes. I truly appreciate it.
@kristofs8893
@kristofs8893 2 жыл бұрын
I had no chance of understanding Coroutines, but you made it look so simple!
@StevdzaSan
@StevdzaSan 2 жыл бұрын
Yay, happy to hear that buddy!
@Axelfromthehudjelud
@Axelfromthehudjelud 2 жыл бұрын
Ok, this is the best explanation of the things that were confusing me. Thank you very much!
@100rabhGrwal
@100rabhGrwal 3 жыл бұрын
Thankyou dear for this easy and understandable explanation 👍
@adrienchew
@adrienchew 3 жыл бұрын
Thank you for all the good content!
@TheDamiankain
@TheDamiankain Жыл бұрын
It amazes me how quickly and easily this topic can be explained and shown !!!
@kmcgill88
@kmcgill88 2 жыл бұрын
Thanks!
@StevdzaSan
@StevdzaSan 2 жыл бұрын
Thank you! ❤
@ashwin_mahajan
@ashwin_mahajan 3 жыл бұрын
Very well explained and demonstrated, thank you. 🙌
@kwesiamartey
@kwesiamartey 3 жыл бұрын
That is my man never disappoint, You are the best
@adwatt357
@adwatt357 2 жыл бұрын
Loved your explanation style !! Keep up the good work !!
@stasleonov5196
@stasleonov5196 Жыл бұрын
It is amazing! I finally understand what happen when we use lifecyclescope
@shadiossaili7377
@shadiossaili7377 3 жыл бұрын
Yes please do more videos like this!
@TheInvisibleWasTaken
@TheInvisibleWasTaken 3 жыл бұрын
You are amazing. Thanks for the content.
@nesibeyyubov554
@nesibeyyubov554 3 жыл бұрын
best explanation ever, thanks too much
@vaibhavarora8793
@vaibhavarora8793 3 ай бұрын
Thank You , It was very useful.
@Another0neTime
@Another0neTime 3 жыл бұрын
The best!
@michaelappiah-kubi2829
@michaelappiah-kubi2829 8 ай бұрын
Thank you
@slobom.6744
@slobom.6744 Жыл бұрын
Great Explanation, thanks bro
@Mkumarei
@Mkumarei 3 жыл бұрын
Thank you ...
@nicolasvantsis6166
@nicolasvantsis6166 3 жыл бұрын
Very nice
@anudeepananth
@anudeepananth 3 жыл бұрын
So there is no way to use a LifecycleScope or ViewModelScope inside of an Adapter class?
@giorgikakhetelidze2115
@giorgikakhetelidze2115 2 жыл бұрын
What is difference between CoroutineScope and GLobalScope about their lifcecycles? when CoroutineScope Cancells autmatically?
@pavelgera72
@pavelgera72 Жыл бұрын
хорошие видео для понимания
@turtle733
@turtle733 2 жыл бұрын
+1 thank you :)
@ajayvamsee7508
@ajayvamsee7508 7 ай бұрын
So you mention global scope coroutine will run even fragment A is destroyed but after again come back to fragment A the fragment A will start again right then coroutine will start again.. So we have 2 coroutines or what will happens..?
@pinoy_marites_beh
@pinoy_marites_beh Жыл бұрын
what if you created an infinite loop without using "delay" and instead system time difference, I think it will not be cancelled even if the coroutine is tied to the lifecycle.
@sumit180288
@sumit180288 3 жыл бұрын
Make a detailed video on Coroutine Jobs
@baur22
@baur22 3 жыл бұрын
Will there be a jetpack compose course?
@StevdzaSan
@StevdzaSan 3 жыл бұрын
Definitely in the future
@roushanali1918
@roushanali1918 2 жыл бұрын
I like this... but want to know is there any better content for proffessionals?
@nileshdhawale2138
@nileshdhawale2138 3 жыл бұрын
When u create video use android studio default theme, it will be very clear for visibility as compare to dracula theme
Jobs and Cancellation -  Kotlin Coroutines
14:29
Stevdza-San
Рет қаралды 18 М.
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 15 МЛН
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 63 МЛН
Despicable Me Fart Blaster
00:51
_vector_
Рет қаралды 28 МЛН
Kotlin Flows in a Nutshell
13:59
Philipp Lackner
Рет қаралды 58 М.
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 35 М.
Be VERY Careful with GlobalScope
13:55
CodingWithMitch
Рет қаралды 13 М.
5 Fatal Coroutine Mistakes Nobody Tells You About
18:15
Philipp Lackner
Рет қаралды 85 М.
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 808 М.
Nature's Incredible ROTATING MOTOR (It’s Electric!) - Smarter Every Day 300
29:37
Everything you need to know about Kotlin 2.0 🟣
11:05
Stevdza-San
Рет қаралды 61 М.
Pydantic is all you need: Jason Liu
17:55
AI Engineer
Рет қаралды 172 М.
Kotlin Coroutines 101 - Android Conference Talks
24:49
Android Developers
Рет қаралды 133 М.
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 15 МЛН