Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynctask heavy usage

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?

like image 982
tony9099 Avatar asked Sep 24 '13 15:09

tony9099


2 Answers

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)

like image 146
Augusto Avatar answered Oct 06 '22 11:10

Augusto


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.

like image 34
telkins Avatar answered Oct 06 '22 09:10

telkins