Can “experimental” Kotlin coroutines be used in production?

UPDATE: Kotlin coroutines are no longer experimental as of Kotlin 1.3. Kotlin coroutines can and should be used in production. That was the chief reason to officially release them in Kotlin 1.1. Having released them, the JetBrains team had committed to maintain backwards compatibility with respect to any changes that are introduced to them in … Read more

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution > java.lang.reflect.InvocationTargetException (no error message)

Android Studio’s UI was just hiding the error… when the error occurred, it highlighted the item in the list view, and showed an unhelpful message in the terminal view. to find the real error, select the root item in the list view so that Android Studio would display the whole build output in the terminal … Read more

GlobalScope vs CoroutineScope vs lifecycleScope

First, let’s start with definitions to make it clear. If you need a tutorial or playground for Coroutines and Coroutines Flow you can check out this tutorial/playground i created. Scope is object you use to launch coroutines that only contains one object which is CoroutineContext public interface CoroutineScope { /** * The context of this … Read more

Existing 3-function callback to Kotlin Coroutines

In this particular case you can use a general approach to convert a callback-based API to a suspending function via suspendCoroutine function: suspend fun CameraManager.openCamera(cameraId: String): CameraDevice? = suspendCoroutine { cont -> val callback = object : CameraDevice.StateCallback() { override fun onOpened(camera: CameraDevice) { cont.resume(camera) } override fun onDisconnected(camera: CameraDevice) { cont.resume(null) } override fun … Read more

Difference between a thread and a coroutine in Kotlin

What does it mean that a coroutine is like a lightweight thread? Coroutine, like a thread, represents a sequence of actions that are executed concurrently with other coroutines (threads). What is the difference? A thread is directly linked to the native thread in the corresponding OS (operating system) and consumes a considerable amount of resources. … Read more

Kotlin: withContext() vs Async-await

Large number of coroutines, though lightweight, could still be a problem in demanding applications I’d like to dispel this myth of “too many coroutines” being a problem by quantifying their actual cost. First, we should disentangle the coroutine itself from the coroutine context to which it is attached. This is how you create just a … Read more

The AsyncTask API is deprecated in Android 11. What are the alternatives?

You can directly use Executors from java.util.concurrent package. I also searched about it and I found a solution in this Android Async API is Deprecated post. Unfortunately, the post is using Kotlin, but after a little effort I have converted it into Java. So here is the solution. ExecutorService executor = Executors.newSingleThreadExecutor(); Handler handler = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)