Skip to content

Instantly share code, notes, and snippets.

@mttkay mttkay/DownloadTask.java
Last active Dec 21, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.