I had similar issues. I managed to fix the performance of the list-
view, but i ran into memory issues.

My app downloads images from Smugmug, images that are 'front-page'
images of galleries/albums.
First, my app needed to get the information about the album, to get
the image-id of the album's front-page image. This would result in a
URL and then my app downloads the image using this URL and then shows
it in a list-item.

I used the ExecutorService to fetch the necessary album information
and image-retrieval and image decoding in a limited number of
background threads.

In the list-adpater's getView method, i would tag (setTag) the list-
item view with the album-id and submit a new (cancelable) task using
the ExecutorService (java.util.concurrent packages). This task
downloads the album info and then downloads the image. While the album
information and the image were downloading, i showed a place-holder
picture in my list-item's imageview (a bitmap from the res/drawable
directory)

When the task that has been submitted finishes, it posts the result
back to the main-thread: Loop over the current list-view children
(which are the visible list-items). For each child get its tag
(getTag) and if this tag matched the task-result, i would set the
child's imageview's bitmap to the image i just downloaded.

This all worked quite well, with images downloading at their own pace
and the list-view kept performing well.
However, at some point i got memory errors when calling
ImageView.setImageBitmap(Bitmap). I checked my code. I made sure to
recycle not-used bitmaps, i did not cache bimtaps, etc., but i kept
getting memory errors (note that the smugmug images downloaded were
small: 100x100 pixels).

I was not able to solve these memory errors and i abandoned this idea.
Any ideas to prevent these memory errors? :-)

On Mar 17, 7:28 am, ifuller1 <ifuller1mob...@gmail.com> wrote:
> Thanks gesh - as suggested the problem was related to recycling.
> Preformance is pretty good now, sadly my images keep shuffling but
> given your recent input this should be easy to fix.
>
> On Mar 15, 10:03 pm, Gesh <geo...@neofonie.de> wrote:
>
>
>
> > > I'm currently using the ImageAdapter from the Hello GridView sample.
> > > But loading the images from the web rather than using resources.
>
> > I think you need a better understanding of how adapters work to solve
> > your problem. The getView() method of your Adapter is inkoved every
> > time an image in your grid becomes visible (yes, including when you
> > scroll back and forth to previously visible images). So if you have
> > just replaced that one line image.setImageResource(int) with
> > image.setImageDrawable(Drawable.createFromStream()) it means you are
> > re-downloading images every time they get scrolled into view.
>
> > So you need to cache those downloaded images and while you are at it
> > make sure you cache scaled thumbnail of the image, just as big as you
> > need them to avoid the possible problem Romain suggested. Use
> > Bitmap.createScaledBitmap() - it's worked great for me.
>
> > Also be aware that the emulator is running on your PC using that same
> > network speed. If you want to test for real network problems you might
> > get on a real device try starting the emulator with limited network
> > (or on your G1 disable wireless and 3G). I alwasy run my emulator with
> > network speed and latency set to EDGE, or for some debugging purposes
> > even GPRS or GSM.
>
> > hope that helps you,
> > gesh.
>
> > On Mar 15, 7:22 am, ifuller1 <ifuller1mob...@gmail.com> wrote:
>
> > > Hi Gesh,
>
> > > Thanks for the response. I'll certainly give the bitmap factory a go.
> > > I'm currently using the ImageAdapter from the Hello GridView sample.
> > > But loading the images from the web rather than using resources. The
> > > problem is immediate, in that the performance doesn't degrade after re-
> > > visits to the activity, but is instead directly proportional to the
> > > number of images I'm displaying.
>
> > > As well as trying the bitmap factory can I ask what you think is the
> > > best way to encourage garbage collection? Will nulling my objects be a
> > > big help.
>
> > > Once I have it optimized I'm going to release it for free... I think
> > > there's a big hole in androids picasa support.
>
> > > Ian
>
> > > On Mar 14, 11:38 pm, Gesh <geo...@neofonie.de> wrote:
>
> > > > hi,
>
> > > > I have written 2 connected apps with some image content pulled from
> > > > the web and must say if you handle your resources right it shouldn't
> > > > be a problem at all.
>
> > > > Do you use your own Adapter for theGridViewor do you use some of the
> > > > already available ones in the SDK? If you use your own you should keep
> > > > in mind that when you deal with AdapterViews in general they keep
> > > > references to Views you create in your adapter and recycle them, so
> > > > try to reuse the convertView reference you get in the Adapter.getView
> > > > (int position, View convertView, ViewGroup parent) method.
>
> > > > And although memory leaks are difficult to achieve in what sounds like
> > > > a single activity app the other thing that comes to mind is that you
> > > > might have memory leaks due to the way you use Drawables. Try using
> > > > Bitmaps from the BitmapFactory.decodeStream(InputStream) method and
> > > > maybe read this blog for more info why Drawables could cause memory
> > > > leaks 
> > > > -http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.....
>
> > > > cheers,
> > > > gesh.
>
> > > > On Mar 14, 12:47 pm, ifuller1 <ifuller1mob...@gmail.com> wrote:
>
> > > > > I've managed to successfully connect to the picasa web services using
> > > > > JSON and download a list of thumbnails from my picasa album. The
> > > > > thumbnails are all very small but I'm getting pretty terrible
> > > > > performance (especially when compared to the native picture viewer).
> > > > > As my main goal was getting the application working their is obviously
> > > > > lots of optimisation work I can do but I just wanted to know where the
> > > > > most likely cause of poor performance is coming from. Is it the memory
> > > > > usage (so I should try cleaning up existing objects) or is it display
> > > > > performance (can't cope with 30 thumbnails at once)?
>
> > > > > Example thumbnail 
> > > > > imagehttp://lh6.ggpht.com/_QIFTbqmwS8U/Samo30_xoBI/AAAAAAAAAEk/VeBxiukdKzU...
>
> > > > > being loaded via Drawable.createFromStream
>
> > > > > Thanks in advanced.
>
> > > > > Ian- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to