0

I was trying the hp.android answer in the https://stackoverflow.com/a/6779067/1236259 thread but my activity never invokes the onDestroy method

I have a ListView with images and I call to other activity by:

ImageButton imageButtonSeeMap = (ImageButton)this.findViewById(R.id.imageButtonSeeMap);
imageButtonSeeMap.setOnClickListener(new OnClickListener() {....

From the new activity I invoke the ListView activity again and in this point I´m getting the exeption: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

The image in the listview is created using:

thumb_u = new URL(lp.get(i).getImage());
            thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");

            imageViewPoi.setImageDrawable(thumb_d);

How can I release the memory of the images? The unbindDrawables in the onDestroy method is never invoked.

Any idea?

1
  • You probably can't handle having two lists open at the same time. You also need to make sure to call recycle() on the bitmap when the view is recycled. Also this: new URL(lp.get(i).getImage()); ... thumb_u.openStream(), "src"); is a bad idea. You need to use AsyncTasks and not download "inline". Commented Jun 28, 2012 at 22:06

1 Answer 1

1

Images are beast in android, so OutofMemory exceptions are kinda something you might have to get used to. This should allow your listview to get images from the web and not crash yer app.

Assuming that the 2nd code block is from your ListView's adapter getView() method, try :

try {
    thumb_u = new URL(lp.get(i).getImage());
    thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
    imageViewPoi.setImageDrawable(thumb_d);
} catch (OutOfMemoryError e) {
    System.gc();
    thumb_u = new URL(lp.get(i).getImage());
    thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
    imageViewPoi.setImageDrawable(thumb_d);
}
Sign up to request clarification or add additional context in comments.

2 Comments

"Images are beast" -- I just died in the office.
I used your solution and the problem persist. After hours I noted that one of the images is PNG. I changed to JPG and the the list was populated successfully. Any idea?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.