Skip to content

Instantly share code, notes, and snippets.

@getsadzeg
Last active June 29, 2018 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getsadzeg/d5759333157c050aa3a891356b672cc9 to your computer and use it in GitHub Desktop.
Save getsadzeg/d5759333157c050aa3a891356b672cc9 to your computer and use it in GitHub Desktop.

AsyncTask helps us to do some heavy stuff on the thread other than UI. It allows us to do background operations and then publish to UI.

It must be subclassed and goes like this(for example):

 AsyncTask<Parameters, Progress, Result>

And it has 4 steps: onPreExecute, doInBackground, onProgressUpdate, onPostExecute.

doinBackground implementation:

public resultType doInBackground(ParamType... params) { .. }

onPostExecute:

public void onPostExecute(ResultType result) { .. }

onProgressUpdate:

public void onProgressUpdate(Progress... progress)

And to execute our AsyncTask class, we should do it like this:

new SomeAsyncTask().execute(parameters);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment