Since coroutine is a hot topic in mobile development, converting vanilla JVM callback into Kotlin Coroutines is desirable. The wrapping happens using something called SuspendCoroutine. What is a SuspendCoroutine suspendCoroutine is a builder function that mainly used to convert callbacks into suspend functions. Let’s say for example you have some legacy (or not) Api...
Best Android Image Loaders – 2022
In this article, we will explore some of the best Android image loaders for you. These are some of the most commonly used third-party libraries since Android SDK doesn’t provide a simple image loading solution for developers to use. Generally, you tend to have to implement one yourself or look at third-party libraries. Photo by Tim Gouw on Pexels.com Glide Glide is a fast and efficient open...
Kotlin Scoping Functions apply vs. with, let, also, and run
Functional-style programming is highly advocated and supported by Kotlin’s syntax as well as a range of functions in Kotlin’s standard library. In this post we will examine five Kotlin scoping functions (aka higher-order functions): apply, with, let, also, and run. When learning these five functions, you will need to memorize 2 things: how to use them, and when to use them...
Constraints with Android Worker
Sometimes, we want our app to perform some background tasks under certain conditions, such as Battery level or network etc. With Worker and Constraints, we can conveniently achieve that. The example problem A worker class that prints a message to the console. class MyWorker(context: Context, params: WorkerParameters): Worker(context,params) { override fun doWork(): Result { Log.i(LOG_TAG...
Advanced Keras – Custom loss functions
When working on machine learning problems, sometimes you want to construct your own custom loss function(s). This article will introduce abstract Keras backend for that purpose. Keras loss functions From Keras loss documentation, there are several built-in loss functions, e.g. mean_absolute_percentage_error, cosine_proximity, kullback_leibler_divergence etc. When compiling a Keras model, we often...