Now that we have seen how to use
AsyncTask, we might ask ourselves when we should use it.
Good candidate applications for
AsyncTask tend to be relatively short-lived operations (at most, for a second or two), which pertain directly to a specific
Activity and need to update its user interface.
AsyncTask is ideal for running short, CPU-intensive tasks, such as number crunching or searching for words in large text strings, moving them off the main thread so that it can remain responsive to input and maintain high frame rates.
Blocking I/O operations such as reading and writing text files, or loading images from local files with
BitmapFactory, are also good use cases for
Of course, there are use cases ...