Is the AsyncTasks threading the wrong practice?

I am writing an application that does the following:

  • Scans a web page and extracts image URLs from it.
  • Decodes them before Bitmapand shows them inImageView

I do not want them to run in the user interface thread, and obviously the second point cannot be executed without completing the first.

Can I customize AsyncTasks to achieve this? I mean the beginning of the second of the first method onPostExecute().

Is this considered bad practice? If so, how do I do this?

(this is a theoretical question, I am not asking for code)

+4
source share
5 answers

, AsyncTasks, . : , .

AsyncTasks . AsyncTasks, . . AsyncTasks.

: AsyncTask. : AsyncTasks? , , . AsyncTask, , .


, AsyncTasks , . , AsyncTask, , . , , , - - AsyncTask , , , , , , , .

+3

AsyncTasks ? onPostExecute()

, AsyncTask . , . , .

, ?

. , ExecutorService, /,

+1

, . , , . , : onPreExecute onPostExecute , , doInBackground - - . , AsyncTask doInBackground 1-, onPreExecute onPostExecute . .

+1

, , , .

AsyncTask:

AsyncTasks ( ). , API, java.util.concurrent , , ThreadPoolExecutor FutureTask.

( Promises) - . A - ; .., .

:

Future( calculate and return x).map( consume x and return y)
                               .map ( consume y and so on)
+1

, , . , , , , .

0
source

All Articles