Common AsyncTask issues
As with any powerful programming abstraction, AsyncTask
is not entirely free from issues and compromises.
Fragmentation issues
In the Controlling the level of concurrency section, we saw how AsyncTask
has evolved with new releases of the Android platform, resulting in behavior that varies with the platform of the device running the task, which is a part of the wider issue of fragmentation.
The simple fact is that if we target a broad range of API levels, the execution characteristics of our AsyncTasks—and therefore, the behavior of our apps—can vary considerably on different devices. So what can we do to reduce the likelihood of encountering AsyncTask
issues due to fragmentation?
The most obvious approach is to deliberately target devices running at least Honeycomb, by setting a minSdkVersion
of 11 in the Android Manifest file. This neatly puts us in the category of devices, which, by default, execute AsyncTasks serially, and therefore, much more predictably.
However,...