How to run an expensive calculation with Kotlin Coroutines on the Android Main Thread without freezing the UI

On Android, you should usually perform CPU-intensive tasks on a background thread. Otherwise, if we perform them on the main thread, the UI freezes and gets unresponsive. With Coroutines, however, it is possible to perform expensive computations without ever leaving the main thread and without impacting the functionality of the UI. In this blog post, I show you how this is possible. However, I will also tell you why you should never follow this approach in a real production app.

Read More
 

Do I need to call suspend functions of Retrofit and Room on a background thread?

After publishing my open source project about Coroutines on Android, which currently includes 16 of the most common, real-world use cases of using Coroutines in an Android application, one of the most common questions I get from developers was whether or not we have to switch to a background thread whenever we call a suspend function to make a network request with Retrofit or a database call with Room in order to not block the main thread which would make the UI freeze and get unresponsive.

Read More
 

Understanding Kotlin Coroutines with this mental model

For the majority of developers, the concept of a coroutine is pretty unfamiliar, although the first ideas date back to the early sixties. This is because we started to learn Software Development with programming languages like Java, in which the concept of a coroutine simply does not exist. What we did learn, however, are how basic concepts like classes, functions, and interfaces work. Over time, we developed a fundamental understanding of these essential, yet abstract concepts.

Read More