Are you aware with Asynchronous Programming? Well if you are into android application development, I am pretty sure that you know about Asynchronous Programming. And when you know what is Asynchronous Programming, you also know writing async codes are a kind of headache. But not anymore, here in this Kotlin Coroutines Tutorial for Android, I am going to show you magic 😉.
Yes you heard that right, I will show you magic. I will write asynchronous code, in synchronous manner. And I can do it with the help of Coroutines. When I left java and started using Kotlin for all my projects, I realized how awesome Kotlin is. And with Coroutines, it is just fabulous my friends. It makes writing network calls, and other async stuffs way more easier.
Table of Contents
What is a Coroutine?
The very first question that arises in everyone’s mind. The official android developer page says,
“A coroutine is a concurrency design pattern that you can use on Android to simplify code that executes asynchronously. Coroutines were added to Kotlin in version 1.3 and are based on established concepts from other languages.”
Coroutine is basically a feature added from Kotlin Language 1.3 that super simplifies the asynchronous code.
Why use Coroutine?
We already had number of tools for async programming, then why we need Coroutine? Well this is a fair question that should be asked. We have RxJava, AsyncTask, Threads etc. Then why I should focus on learning a new concept?
But if you are using the above mentioned things, then you already know that how difficult it is to use RxJava correctly. The learning curve of RxJava is also too much. AsyncTask can easily introduce memory leaks in our app. Managing threads are another pain.
But with Coroutines all these shortcomings are fixed. Trust me guys, once you will start using it, you will understand how easy it is to learn and write.
Now, if you convinced you enough that you should learn Coroutines, and start using it in your projects, then let’s start the actual topic that was “Kotlin Coroutines Tutorial for Android”.
Kotlin Coroutines Tutorial for Android
In this playlist we will learn about using Kotlin Coroutines in our Android Project. Even if you are a beginner in android development you can go through this course. The only prerequisites are:
- You must know about using Kotlin Programming Language
- You must know how to use Retrofit to make network calls
It takes a lot of effort to make these courses for you. So I request you all that please help me by sharing my contents with your friends.
Download Source Code
You can get the source code of the project that I used in this Kotlin Coroutines Tutorial for Android here:
Thats all for this post friends. Please give your feedback below in the comment section. Don’t forget to share it with all your friends learning Android Application Development.
Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.
7 thoughts on “Kotlin Coroutines Tutorial for Android – Start using Coroutines in Your App”
How to set internet error message and failure case response.
I think you must go through this course as well.
I have already explained your question here.
Nice tutorial thanks for the update. Where to use viewmodelScope and lifecycle scope.
Everything is explained in the course, watch all videos first. Thank You
Learning Kotlin from your Videos..really helpful ..I want to learn MVVM also..i am new in Android Development.Can u please tell me best way to master Kotlin for Android and MVVM design pattern
hi bela khan,
Nice tutorials i have seen till now. In the above example, whatever the url is provided for retrofit calls is not working i.e., http://api.simplifiedcoding.in/course-apis/recyclerview/movies and http://api.simplifiedcoding.in/course-apis/mvvm/quotes. if we are trying to open the same in the browser we are getting “This site can’t be reached api.simplifiedcoding.in’s server IP address could not be found” and if i run the app in the phone app is getting crash.
Yeah my apis are deleted from the server, so you need to use your own. Search on internet about dummy restful api, and use any dummy api for learning. Or you can check my ktor restful api https://youtu.be/dGln2gzdxq8 tutorial, to learn building apis yourself.