Last active
December 21, 2015 16:19
-
-
Save mttkay/6332584 to your computer and use it in GitHub Desktop.
An 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
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