Introduction
In Android, we often want to perform long-running tasks using the background thread with the help of a thread class.
Basically, an Android application has two types of threads:
- Main Thread(UI Thread).
- Background Thread.
Lets
take one example. We want to download a file from a remote server and update the UI progress bar for showing the file downloading status. For
that we use a background thread to download the file from a remote server,
otherwise, if we initialize a long-running task in Main Thread (UI Thread), the
UI will slow
We can achieve the task with the help of background thread. However, the problem is that we want to update the UI from a background thread. The background thread will not allow us to communicate directly to the main thread.