The problem with today is that calling Bitmapfactory.decodefile (name) from an input stream gets a bitmap error. The first call is no problem, the second call will report the above memory overflow problem. And some mobile phone reported some mobile phone does not report. Study for a half-day finally solved. First, the following reason is analyzed, it should be that the image occupies more memory than the system virtual machine can allocate the maximum limit. Different phones may be assigned the same maximum value. Later the solution was to set the bitmapfactory.options.
bitmapfactory.options option = new Bitmapfactory.options (); Option.insamplesize = 4; try {Bitmap bmp = Bitmapfactory.decodefile (path,option); Holder.icon.setImageBitmap (BMP); } catch (OutOfMemoryError err) {}
Some say to add bitmapoptions.injustdecodebounds = True, but I add the resulting bitmap is null. You can do it after you remove it. Follow the above method to solve the problem. It is better to recycle bitmap when not in use:
if (bitmap! = null &&!bitmap.isrecycled ())
Bitmap.recycle ();
Android Learning--reference images cause memory overflow java.lang.OutOfMemoryError