AsyncTask is designed to be a helper class around Thread and Handler and does not constitute a generic threading framework. AsyncTasks should ideally be used for short operations (a few seconds at the most.)
This is what it says in the documentation.
Speaking network language, How long is 'a few seconds'?
My app will do the following, get an array list from DB, send it to server, get another list (json), send an okay that it received the list, parse the jsons, insert the list inside db, do some other processes in the db, update UI.. (the list can reach to 5000-1000 entries of object instances.)
Is usage of asynctask for such stuff a good idea? I also need to update the gui according to the results of the response from server.
If no, what other alternatives do I have?
I've already did something similar to you. I've downloaded a bunch of images (about 5000), saved it in the SD card and saved a row in a database. I've used Async Task with no issues and I see no problem using it. I recommend you to use a progress bar to show the user what the App is doing and with the option to cancel the task (AsyncTask provides a cancelation mechanism)
See this answer: AsyncTask for long running operations
In summary, long-running AsyncTasks can create memory leaks due to its implementation. It can also cause issues with orientation changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With