Skip to content

Instantly share code, notes, and snippets.

@rosorio02
Forked from sheharyarn/inline-asynctask.java
Created May 27, 2019 17:54
Show Gist options
  • Save rosorio02/b010080667636be79c0d0fc7c09b9f5f to your computer and use it in GitHub Desktop.
Save rosorio02/b010080667636be79c0d0fc7c09b9f5f 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