Skip to content

Instantly share code, notes, and snippets.

@jgilfelt
Created September 21, 2011 09:50
Show Gist options
  • Save jgilfelt/1231694 to your computer and use it in GitHub Desktop.
Save jgilfelt/1231694 to your computer and use it in GitHub Desktop.
Android - AsyncTask with inline callback boilerplate
private void asyncTaskWithInlineCallback() {
// display UI progress indicator
// ...
new MyAsyncTask() {
protected void onPostExecute(Boolean result) {
// dismiss UI progress indicator
// process the result
// ...
}
}.execute(); // start the background processing
}
class MyAsyncTask extends AsyncTask<Void, Integer, Boolean> {
@Override
protected Boolean doInBackground(Void... arg0) {
// do background processing and return the appropriate result
// ...
return true;
}
}
@briandeheus
Copy link

Saved my life, well almost, with this. Thanks!

@hstevanoski
Copy link

Thank you so much! I was searching for answer like this for ages! Very helpful indeed.

@rosorio02
Copy link

Thank you! It's really useful. ☺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment