I have a Gallery and a GridView in my application. Gallery's adapter is based on thumbnail cursor created through query using MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI.
I use this Gallery to choose images to display in GridView. Whenever the user clicks on an image in the Gallery I have to add this image to GridView. Currently, I use an ArrayAdapter<Integer> to store the images in the GridView. The value stored as objects in the ArrayAdapter is the _ID of the thumbnail and getView on GridView looks like this: public View getView(int position, View convertView, ViewGroup parent) { ImageView i = new ImageView(mContext); System.out.println("I am in get view:" + position); int thumbnailId = getItem(position); i.setImageURI( Uri.withAppendedPath (MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + thumbnailId)); i.setScaleType(ImageView.ScaleType.CENTER_CROP); i.setLayoutParams(new GridView.LayoutParams(80, 80)); return i; } Whenever I click on an item in Gallery, getView is called for all visible positions in the GridView (9 images). After, 12-13 images are added to the gridview and I scroll up and down, I get an OutOfMemoryError. Can someone suggest how I can rework to avoid memory errors here. 03-13 02:29:45.456: ERROR/dalvikvm-heap(487): 338322-byte external allocation too large for this process. 03-13 02:29:45.456: ERROR/(487): VM won't let us allocate 338322 bytes 03-13 02:29:45.466: DEBUG/skia(487): xxxxxxxxxxxxxxxxxxxx allocPixelRef failed 03-13 02:29:58.845: DEBUG/AndroidRuntime(487): Shutting down VM 03-13 02:29:58.845: WARN/dalvikvm(487): threadid=3: thread exiting with uncaught exception (group=0x4000fe68) 03-13 02:29:58.845: ERROR/AndroidRuntime(487): Uncaught handler: thread main exiting due to uncaught exception 03-13 02:29:59.045: ERROR/AndroidRuntime(487): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 03-13 02:29:59.045: ERROR/AndroidRuntime(487): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 03-13 02:29:59.045: ERROR/AndroidRuntime(487): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:304) 03-13 02:29:59.045: ERROR/AndroidRuntime(487): at android.graphics.drawable.Drawable.createFromStream(Drawable.java:635) 03-13 02:29:59.045: ERROR/AndroidRuntime(487): at android.widget.ImageView.resolveUri(ImageView.java:477) 03-13 02:29:59.045: ERROR/AndroidRuntime(487): at --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---