AsyncTask’s are mostly presented as a solution to running well-defined computations or tasks. The classic example is a downloader as an AsyncTask which is fed a URL, updates its progress to the UI, and exits when completed. Is there a reasonable (not-too-hacky) way to add/change input to the AsyncTask while it’s running? Perhaps setting up a queue of items that the AsyncTask has to process and then altering that queue from the main application…? Would that ‘break’ the AsyncTask model for example?
AsyncTask’s are mostly presented as a solution to running well-defined computations or tasks. The
Share
Yes you can. AsyncTask is a thread that has already buited in communication mechanisms to the UI thread. However this communication is only from
AsyncTasktoUIand not in the reverse direction as you need.Also, the maximum number of simultaneous
AsyncTaskin Android is 1 in several API versions.To implement thread safe communication from
UItoAsyncTaskyou will need to useHandlerorBlockingQueueclasses.Personally, I wouldn’t do it. I would use directly a
Threadwith aHandlerorBlockingQueue.Regards.