No, this approach is not correct for a simple reason. Depending on the version you're running, two AsyncTask
s may not be able to run concurrently:
https://groups.google.com/forum/?fromgroups#!topic/android-developers/8M0RTFfO7-M
You can use AsyncTask.executeOnExecutor(...)
to override this behavior but still, you will be targeting systems starting from API 11, which is approximately 60% of the available devices:
http://developer.android.com/about/dashboards/index.html
Moreover, AsyncTask
is not designed for long running operations since they can easily be killed by the system to retrieve memory. And may cause memory leaks if it holds references to an activity which is no longer used.
Use your own Thread
s and possibly use an Handler
to notify the UI Thread. Also take a look here:
Android AsyncTask for Long Running Operations
where RoboSpice is suggested as an out-of-the-box safe-alternative to AsyncTask.