Last active
March 30, 2020 10:01
-
-
Save sheharyarn/5f66a854ce43e0c90521 to your computer and use it in GitHub Desktop.
Android in-line AsyncTask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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