Usually AsyncTask used / created with parameters ... AsyncTask<Params, Progress, Result> . Parameter Values:
Params: These are the
Objects that you pass to
doInBackground() . For example, if I initialize
Params as a
String , now I can access the string parameter using
doInBackground(String... params) from
params[0] ,
params[1] , etc. This is one of the most important parameters that you specify that when calling
AsyncTask you can send the parameter needed in the
doInBackground stream. like new
AsyncTask().execute(string);Progress: When using
AsyncTask , activity is usually used to load content, etc. You can use the progress parameter to give the context to the user that everything is going as it should. Suppose you are blocking the user interface by telling your user that he is loading content. With this progress, you can indicate how much of your content has been downloaded. If, for example, this parameter is an
integer , I could call
publishProgress() on the
doInBackground stream to show the progress in the currently loaded content.
Result: This is usually the only parameter that is allowed to interact with the user interface. Suppose you are finished loading your content. And I would like to indicate that the operation is completed, showing a message about successful completion. Here you do it. For example, you would like to return a
String message stating that the download is complete. In the
doInBackground stream
doInBackground you
return string; in the end. Thus, this value is passed to
onPostExecute(String result) . From there you can set
textView.setText(result) .
Basically AsyncTask is based on the principle of GENERICS and VARARGS (Java concepts)
GENERICS implies that a parameter in AsyncTask can be of any type and VARARGS, indicating that you can send multiple values ββinside these parameters.
In this case, since you are not doing anything significant to change the user interface, you can call AsyncTask<Void, Void, Void> . For a better understanding of AsyncTask you can see the following example .
It reads a long time, but hope this clears things up :)