Some kind of turn for asynthesis

Hi I have a ListView with a list of files. I click an item and start loading this file in asynctask. then I click another, and it needs to be queued, wait for this file and start downloading after it finishes. Can I create some class that will contain all the clicks and pass it to the asynctask download part? and handle them with something. but want to know if this is correct? any links to suggestions? thanks

+6
source share
3 answers

If you are set to use AsyncTask, then yes, hold your clicks and start new tasks when necessary. It should be noted that AsyncTask is similar to the "pocket knife" for streaming in Android applications.

If you really need to manage a set of background tasks, and it sounds like you, take a look at ThreadPoolExecutor. You get more flexibility. BlockingQueue ThreadPoolExecutor More Example

+9
source

Even though the old one got here from Google: consider the IntentService.

+2
source

Take a look at HandlerThread and the Handler class. You need one handler to transfer tasks to the background HandlerThread, and another to stream the user interface to send the results back to the user interface

+1
source

Source: https://habr.com/ru/post/885885/


All Articles