Coroutines in Android


In this blog, I will tell you how you can work with Kotlin coroutines and what is that if you are working with android you have familiar about thread or multithreading concept in java and we can also use thread in Kotlin as well but we generally do not use it directly because we have to do some large task in background and view in UI somehow this can be typical and take a lot of memory and CPU resources of your mobile phone.

what are coroutines?
coroutines can be understood like lightweight thread in android. when you block a thread by thread.sleep method it blocks a whole thread which is not a proper and efficient way In coroutines we can easily do it by delay method and it will not block a thread.

add this line in dependency-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'

code implementation -

This type as given above we call coroutines in android for background task and when the task completes we can update UI in Main Thread.



                                       Download Project- Click me


Post a Comment

0 Comments