Reading Time: 2 minutes

Multitaskers

Humans are notoriously bad multitaskers. Even though we convinced ourselves we’re not. Science shows as soon as we start to do multiple things at the same time, our concentration drops, we get sloppy and errors ramp up. Computers on the other hand are excellent multitaskers. Every modern computer can do many, many things at the same time, switching effortlessly between tasks, without ever dropping the ball.

Concurrency

Software that enables this concurrent computing is off course written by humans. Nevertheless, writing correct scalable software that supports concurrency is hard. This is why there are a lot of libraries to help developers with this task. Since 2005 when the first consumer multicore CPU was introduced, the number of cores in CPU’s are steadily increasing. So if we want to keep leveraging all this computing power, this challenge becomes increasingly important.

Android

Android lives in the JVM world and mostly uses Threads for concurrency. For years the default library to use on Android for concurrent programming was RxJava. It provided an abstraction over Threads and made switching between them easy. But it came with a very steep learning curve and was quite a heavy library to include in your app. But there is a new kid on the block; Kotlin coroutines. Since it’s inception in 2017 it has gained rapid traction. In 2019 Google made it the official recommended library to use when writing concurrent and/or asynchronous code on Android. As a result many new AndroidX libraries use coroutines and flow.

Kotlin Flow

Recently the coroutines API has expanded a lot with the addition of different kind of Flows. There are already excellent in depth articles and documentation about coroutines (see; onetwothree). My article will merely provide a cheat sheet on the Flow API in coroutines for use on Android. What kind of Flows are there, their differences, what are the RxJava equivalents and where can you find a quick snippet to get you started. Happy coding!

Written by Remy Benza

Software Engineer

Waking up Remy in the middle of the night? Rather not! No? Well, there’s one exception: start talking to him about translating creative ideas into nice apps with a pixel perfect (yes, he actually said it!) design, and he will be all ears and wide awake. He also likes to chase tennis balls. Not at the office, but at his favourite tennis court.

Published on: March 22nd, 2021

Newsletter

Become an app expert? Leave your e-mail.

nederlandse loterij en egeniq
pathe thuis en egeniq
rpo and egeniq
mvw en egeniq
rtl and egeniq