Skip to content

Instantly share code, notes, and snippets.

@JenkinsDev
Created November 10, 2013 20:23
Show Gist options
  • Save JenkinsDev/7403437 to your computer and use it in GitHub Desktop.
Save JenkinsDev/7403437 to your computer and use it in GitHub Desktop.
Basic AsyncTask layout that I point people to when they are confused.
public class MyAsyncTaskName extends AsyncTask<String, Integer, String> {
// String: The first string is the parameter, this is what is passed to doInBackground()
// Integer: The first, and only, Integer type is used for progress updates, this is what is passed to onProgressUpdate()
// String: The second String is for what is returned by doInBackground() and what is passed to onPostExecution();
@Override
protected void onPreExecute() {
// Handles what happens before the AsyncTask fully executes.
// Here you can do things like add a progress bar, loading animation, etc.
}
@Override
protected String doInBackground(String... urls) {
// Handles the meat of the AsyncTask.
}
@Override
protected void onProgressUpdate(Integer... progress) {
// Handles progress updating, use this to update a progress bar, etc.
}
@Override
protected void onPostExecute(String result) {
// Handles what happens after the AsyncTask execution ends.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment