I have classic AsyncTask to load image:
private class DownloadImageTask extends AsyncTask<String,Void,Bitmap> {
Bitmap bitmap = null;
@Override
protected Bitmap doInBackground(String... str) {
try{
InputStream in = new java.net.URL(picture).openStream();
bitmap = BitmapFactory.decodeStream(new SanInputStream(in));
//viewPicture.setImageBitmap(bitmap);
viewPicture.setBackgroundDrawable(new BitmapDrawable(bitmap));
}
catch(Exception e){
e.printStackTrace();
}
return bitmap;
}
}
But loading of image is to long. When I start this activity, everything is loaded besides image and only after waiting a second I can see it. What is the problem?
should be done on the UI thread, in the onPostExecute method of your AsyncTask.
Also, close the stream (if !null) you use with a nice finally block of your try/catch.
And don’t worry about the time, it’s the way to go.