Skip to content

Instantly share code, notes, and snippets.

@mttkay
Last active December 21, 2015 16:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mttkay/6332584 to your computer and use it in GitHub Desktop.
Save mttkay/6332584 to your computer and use it in GitHub Desktop.
An AsyncTask.
class DownloadTask extends AsyncTask<String, Void, File> {
protected File doInBackground(String... args) {
final String url = args[0];
try {
byte[] fileContent = downloadFile(url);
File file = writeToFile(fileContent);
return file;
} catch (Exception e) {
// ???
}
}
protected void onPostExecute(File file) {
Context context = getContext(); // ???
Toast.makeText(context,
"Downloaded: " + file.getAbsolutePath(),
Toast.LENGTH_SHORT)
.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment