I've run into this issue before, where dynamically downloading images from the web had a severely negative impact on the user experience (i.e. pretty much froze the UI thread!)
The first solution that I tried was to spawn a new thread for each image I wanted to download (e.g. downloading musical artist images). This ended up in many different threads being spawned and was only marginally better than doing all the work in the UI thread. What worked the best was to create a separate ImageDownloader class which maintained a queue (make sure to use a data structure that is synchronized) of URLs that needed to be downloaded. Then your client code can just make a call to add something to the download queue, passing the ImageDownloader a URL and some kind of unique ID to identify the retrieved image. You can use a Handler in the client code which the ImageDownloader can call with the retrieved image and the unique id; based on the id, the client code can decide what needs to be done with the image. this seemed to work pretty well for me; so much so that even scrolling through a ListView, I was able to dynamically download images as their list elements came into view, without much impact on the smoothness of scrolling... (I'm sure there are better ways still to do this, but this worked well enough for what i needed it for :) Also, I found the code on this page: http://www.anddev.org/gallery_with_remote_images-t769.html very helpful in downloading an image from the web and encoding it as a Bitmap to use within my ANdroid code. Good luck! Dan On Jan 7, 7:02 pm, Jamie <[email protected]> wrote: > what about putting each download in its own thread?? doesnt this > speed things up on the processing side?? Download is still limited to > connection speeds, but you should be able to use a Runnable() in > threads to process each one individually. > > On Jan 7, 7:55 am, Mike Reed <[email protected]> wrote: > > > We don't support async image decoding yet (ala push model). > > > On Tue, Jan 6, 2009 at 11:50 PM, [email protected] > > > <[email protected]> wrote: > > > > Hi > > > > I am using the following code to display an image from the internet > > > > ImageView i = new ImageView(mContext); > > > i.setImageDrawable(getDrawable("http://www.google.com/images/ > > > nav_logo3.png")); > > > ... > > > > public Drawable getDrawable(String imgUrl) { > > > try { > > > URL url = new URL(imgUrl); > > > InputStream is = (InputStream) url.getContent(); > > > Drawable d = Drawable.createFromStream(is, "src"); > > > return d; > > > } catch (MalformedURLException e) { > > > e.printStackTrace(); > > > return null; > > > } catch (IOException e) { > > > e.printStackTrace(); > > > return null; > > > } > > > } > > > > but I would like to be able to load the image asynchronously so that > > > if I want to display a list of 10 images then the text would start to > > > render and then images would load one after the other (like a > > > browser...) . The problem with every code that I have seen so far is > > > that it is all synchronous that is not really good for user > > > experience. I am sure I am missing somthing and would really > > > appreciate your help > > > > thanks > > > > jb --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

