Skip to content

Instantly share code, notes, and snippets.

@fabian7593
Forked from sheharyarn/inline-asynctask.java
Created April 2, 2017 05:55
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 fabian7593/a430e25040ebbd659fa9215aec95b4dc to your computer and use it in GitHub Desktop.
Save fabian7593/a430e25040ebbd659fa9215aec95b4dc 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