AsyncTask parameters. How to get them right?
Question: How to memorize the parameters used in AsyncTask?
Answer: Don’t.
What is an AsyncTask?
An AsyncTask
is background task which runs in the background thread. It takes an Input, performs Progress and gives Output.
ie
AsyncTask<Input,Progress,Output>
.
What makes it so confusing?
In my opinion, the main source of confusion comes when we try to memorize the parameters in the AsyncTask
.
The key is DON’T MEMORIZE.
If you can visualize what your task really needs to do then writing the AsyncTask
with the correct signature would be a piece of cake.
Just figure out what your Input, Progress, and Output are and you will be good to go.
Example:
What is the relationship?
Between AsyncTask
and doInBackground()
doInBackground()
and onPostExecute(),
onProgressUpdate()` are also related
Show me the code!
How will you run this Task?
new DownLoadTask().execute("Paradise.mp3");
Putting up content takes a lot of time and effort 😓.
👏 clap 👏 If you think you learned something from this article.You can find me on Stackoverflow,Github,and,on Linkedin.
Give feedback and feel free to correct mistakes.