Search code examples
androidandroid-asynctask

Type of argument/value that is passed in a AsyncTask


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


Solution

  • 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