1

I am displaying images in ViewPager. The images displayed occupy a lot of space. After showing few images, it throws java.lang.outofMemoryError: Bitmap size exceeds VM bugdet.

Any suggestions on what might be going wrong?

public Object instantiateItem(View pager, int position) {

    LayoutInflater inflater = (LayoutInflater) pager.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.fotopager_buttons, null);

    TextView text = ((TextView) view.findViewById(R.id.textView1));
    text.setText(Global.totalpaging_titlearray[position]);

    TextView textprice = ((TextView) view.findViewById(R.id.textprice));
    textprice.setText("SAR " + Global.totalpaging_pricearray[position]);

    TextView textdesc = ((TextView) view.findViewById(R.id.textdescription));
    textdesc.setText(Global.totalpaging_descarray[position]);

    ImageView imageView1 = ((ImageView) view.findViewById(R.id.image));
    bimage = getBitmapFromURL(Global.totalpaging_array[position]);
    imageView1.setImageBitmap(bimage);
    ((ViewPager) pager).addView(view);

    return view;
}
Rumit Patel
  • 8,830
  • 18
  • 51
  • 70
Soniya
  • 21
  • 6
  • plz refere to my answer in: http://stackoverflow.com/questions/11133645/imageview-outofmemoryexception/11133787#11133787 – Nermeen Jul 05 '12 at 12:56
  • @ M Mohsin Naeem: I had googled a lot and then only posted the question. – Soniya Jul 05 '12 at 13:07
  • 1
    @nunu: i don't want to resize the bitmap, but I want to manage the memory management using releasing the drawable object. – Soniya Jul 05 '12 at 13:10

2 Answers2

0

From what I understand, you are displaying images on the pages of view pager. How many pages does your view pager hold?

If your bitmaps in one page exceed the VM budget, consider resizing your bitmaps or decode to a low memory color format such as RGB565 or ARGB444.

Without code it is not possible to figure out whether you are instantiating the pages for the view pager properly. Can you post the code for your PagerAdapter class instantiateItem(View view, int position) method?

Supreethks
  • 597
  • 6
  • 16
  • @Soniya You haven't shown the code for `getBitmapFromURL()` method. I guess you have used Bitmap Factory to download the bitmap from url. Anyways [here is a page](http://developer.android.com/training/displaying-bitmaps/load-bitmap.html) I can point to to handle large Bitmaps – Supreethks Jul 06 '12 at 13:23
0

You are getting this issue before the images are very large. They are very high-resolution images and hence have very large size. Try reducing the size or resolution of these images using any software like photoshop.