So, I\'m working on a barcode decoder, which once we have the barcode goes to multiples API over the internet to decode what was just scanned. The thing is that I have to li
In situations like this it might be better to batch long running operations together in one AsyncTask.
Another option is to use the Loaders API, this makes chaining tasks much easier http://developer.android.com/guide/topics/fundamentals/loaders.html
You can go for another approach if you are facing often a situation like this. That is to merge requests and operations inside of runnables/callables and to manage them separately within say a queue for instance. Here is a nice approach. http://ugiagonzalez.com/2012/07/02/theres-life-after-asynctasks-in-android/
I think it's absolutely legitimate to start the second AsyncTask
in the onPostExecute
of the first AsyncTask, Mixing both operations is a bad logical idea, As "The Offspring" said - "You've gotta keep 'em separated"
If you don't want it to be directly inside the onPostExecute
itself, set a handler to execute it in the activity and call this handler from onPostExecute
.
And last thing - If you have a lot of logic - move it to a separate file, don't keep it all at the same file.