1

Just 3 simple questions about AsyncTasks. If we declare this AsyncTask:

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long>

1- What type of value is passed to doInBackground() method? Is it URL?

2- What type of value is passed to the callback that informs the task progress?

3- What type of value is passed to the callback that is executed when the task ends?

Thank you all. Rest of a good day

João Costa
  • 57
  • 1
  • 1
  • 9

2 Answers2

2

AsyncTask consists of Input Parameter Type, Progress Parameter Type, Result Type respectively. So in your case

DownloadFilesTask extends AsyncTask<URL, Integer, Long>

URL is the Input Parameter Type

Integer is the Progress Parameter Type

Long is the Result Type

  1. What type of value is passed to doInBackground() method? Is it URL?

    Answer: Yes its the URL

  2. What type of value is passed to the callback that informs the task progress?

    Answer: its Integer

  3. What type of value is passed to the callback that is executed when the task ends?

    Answer : Its Long value and it is the value that is expected to return from doInBackground and passed as a callback to onPostExecute`.

For Reference

Faisal Naseer
  • 4,110
  • 1
  • 37
  • 55
1

The three types used by an asynchronous task are the following:

  • Params, the type of the parameters sent to the task upon execution.
  • Progress, the type of the progress units published during the background computation.
  • Result, the type of the result of the background computation.

private class MyTask extends AsyncTask<Params, Progress, Result> { ... }

So, to answer your question, URL is passed to doInBackground and Long is the return type.

Read more https://stackoverflow.com/a/6053673/5644761

JakeB
  • 2,043
  • 3
  • 12
  • 19