michael m wrote:
> What I am doing, which I question, is loading each image via a thread
> as it is retrieved from the ImageCache...I pass back a default image
> if the bitmap is null, then update the default image in the ImageViews
> with the Bitmap is loaded from the sdcard; I'm doing this by posting
> to a Handler in the Adapter from the thread that loads the image.

I suspect you are going to get in trouble with that many threads.

> So if the number of threads is the problem I'm thinking of loading all
> the bitmaps when the app is first initiated, probably using the
> AsyncTask class. 

That is probably too far in the other extreme.

> A question I have though about this is that the docs
> say that you can only call execute() once...what's happens if some of
> my Bitmaps are garbage collected??  Do I then call individual threads
> to reload?  I've looked through some of the Google apps, Shelves and
> Photostream, but they don't seem to be using Bitmaps wrapped in
> SoftReferences.

I've wrapped up this pattern in a ThumbnailAdapter:

http://github.com/commonsguy/cwac-thumbnail/tree/master

Basically, I use AsyncTaskEx, which is my fork of AsyncTask that allows
for 10 parallel threads -- not infinite, but not only 1.

I also gave up on SoftReferences, as posts in this list from a month or
two ago gave me the impression that SoftReferences are effectively
pointless with the current Dalvik garbage collection implementation.
Instead, I use an LRU cache, (re)loading images on demand via AsyncTaskEx.

It may be, though, that ThumbnailAdapter will "just work" for you,
though I have not tried it for images starting on the SD card -- I was
focused on caching them off the Internet. I don't have much in the way
of documentation at this point, but there is a sample app in the github
project. While I suspect I'll be upgrading the implementation in the
coming months, the "API" (put the URL of the image to be loaded in the
ImageView's setTag()) should remain constant.

If you give it a whirl and run into problems, ping me on the cw-android
Google Group, and I may be able to help:

http://groups.google.com/group/cw-android

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android Development Wiki: http://wiki.andmob.org

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to