Skip to content

Instantly share code, notes, and snippets.

@sheharyarn
Last active March 30, 2020 10:01
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save sheharyarn/5f66a854ce43e0c90521 to your computer and use it in GitHub Desktop.
Save sheharyarn/5f66a854ce43e0c90521 to your computer and use it in GitHub Desktop.
Android in-line AsyncTask
// The Very Basic
new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
// Pre Code
}
protected Void doInBackground(Void... unused) {
// Background Code
return null;
}
protected void onPostExecute(Void unused) {
// Post Code
}
}.execute();
// Return something from `doInBackground` to `onPostExecute`
new AsyncTask<Void, Void, String>() {
protected String doInBackground(Void... params) {
// Background Code
return "message";
}
protected void onPostExecute(String msg) {
// Post Code
// Use `msg` in code
}
}.execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment