Created
October 18, 2011 07:13
-
-
Save takuo/1294791 to your computer and use it in GitHub Desktop.
Android code snippet - using 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
public void onClick(View v) { | |
new DownloadImageTask().execute("http://example.com/image.png"); | |
} | |
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { | |
/** The system calls this to perform work in a worker thread and | |
* delivers it the parameters given to AsyncTask.execute() */ | |
protected Bitmap doInBackground(String... urls) { | |
return loadImageFromNetwork(urls[0]); | |
} | |
/** The system calls this to perform work in the UI thread and delivers | |
* the result from doInBackground() */ | |
protected void onPostExecute(Bitmap result) { | |
mImageView.setImageBitmap(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment