AsyncTask

As you have may have noticed, we are already using the AsyncTask class in our application. Now, we will go one step forward with it--we will run it on the executor. Why would we do that?

First of all, by default, all AsyncTasks are executed in sequence by Android. To execute it in parallel, we need to execute it on the executor.

Wait! There is more. Now, when we execute tasks in parallel, imagine you executed a few of them. Let's say we start with two. That's fine. They will perform their operations and report us when completed. Then, imagine we run four of them. They will work too, in most cases, if the operations they execute are not too heavy. However, at some point, we run fifty AsyncTasks in parallel.

Then, your application ...

Get Mastering Android Development with Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.