My application loads 12 100x100 thumbnail images from the web using
the code below.  I then display the thumbnails in a GridView using an
ImageAdapter derived from BaseAdapter.  I'm running into memory issues
because each of the thumbnails is held in memory as a Bitmap.

This seems like a fairly straightforward application (display a
gallery of thumbnails from the web), can some give me advice on how to
reduce my memory needs?  Maybe there's a better way to display web
images in a GridView that doesn't involve downloading and storing each
one as a Bitmap?


                // Download a Bitmap thumbnail for each photo
                Bitmap bm;
                HttpGet httpRequest;
                HttpClient httpclient;
                HttpResponse response;
                HttpEntity entity;
                InputStream instream = null;
                BufferedHttpEntity bufHttpEntity;
                for (Photo photo : photos) {
                        try {

                                httpRequest = new HttpGet(photo.getThumbnail());

                                httpclient = new DefaultHttpClient();
                                response = (HttpResponse) httpclient
                                                .execute(httpRequest);

                                entity = response.getEntity();
                                bufHttpEntity = new BufferedHttpEntity(
                                                entity);
                                instream = bufHttpEntity.getContent();

                                bm = BitmapFactory.decodeStream(instream);

                                photo.setBm(bm);
                                listener.onPhotoDownloadListener(photo);
                        } catch (Exception e) {

                        } finally {
                                try {
                                        if (instream != null) {
                                                instream.close();
                                        }
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        }
                }

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