Concurrency in Android
If you are an Android user, you are probably aware of ANR messages. It might not ring a bell for you, so take a look at the following image:
Activity Not Responding (ANR) happens when there is code running in the UI or main thread that blocks user interaction for more than 5 seconds.
In Android, an application runs a single thread, called the User Interface thread. We will explain what a thread is in a way that even readers with no programming background will understand. We can visualize a thread as a column of instructions or messages executed by the CPU. These instructions come from different places; they come from our application as well as the OS. This thread is used to handle the response from the user, lifecycle methods, and system callbacks.
The CPU processes messages sequentially, one after another; if it's busy, the message will wait in a queue to be executed. Therefore, if we perform long operations in our application and send many messages to the CPU...