错误提示05-21 07:00:05.659: E/dalvikvm-heap(974): 64240-byte external allocation too large for this process.
05-21 07:00:05.688: E/GraphicsJNI(974): VM won't let us allocate 64240 bytes
05-21 07:00:05.688: D/skia(974): --- decoder->decode returned false图片加载到300张左右的时候就出现了上面的错误,用mat分析内存共2.4M各位给点意见呀
05-21 07:00:05.688: E/GraphicsJNI(974): VM won't let us allocate 64240 bytes
05-21 07:00:05.688: D/skia(974): --- decoder->decode returned false图片加载到300张左右的时候就出现了上面的错误,用mat分析内存共2.4M各位给点意见呀
http://download.csdn.net/detail/fire_fire_fire/4317821
看里面的onActivityResult方法,这里面做了内存溢出处理。
Map<String, SoftReference<Drawable>> cache = new HashMap<String, SoftReference<Drawable>>();
调用:String strurl = "图片路径";
CallbackImg iCallBack = new CallbackImg(imageView);//imageView为界面的控件
Drawable drawable = asyncImageLoad.getDrawable(strurl, iCallBack);
if (drawable != null) {
imageView.setImageDrawable(drawable);
}AsyncImageLoad :public class AsyncImageLoad {
private Map<String, SoftReference<Drawable>> cache = new HashMap<String, SoftReference<Drawable>>(); public Drawable getDrawable(final String strurl, final ICallBack iCallBack) {
if (cache.containsKey(strurl)) {
SoftReference<Drawable> soft = cache.get(strurl);
if (soft.get() != null) {
return soft.get();
}
} final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
iCallBack.loadImage((Drawable) msg.obj);
}
}; new Thread() {
@Override
public void run() {
Drawable drawable = loadForUrl(strurl);
if (drawable != null) {
cache.put(strurl, new SoftReference<Drawable>(drawable));
Message msg = handler.obtainMessage(0, drawable);
msg.obj = drawable;
handler.sendMessage(msg);
}
}
}.start(); return null;
} protected Drawable loadForUrl(String strurl) {
try {
URL url = new URL(strurl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
Drawable drawable = new BitmapDrawable(bitmap);
return drawable;
} catch (Exception e) {
return null;
}
} public interface ICallBack {
void loadImage(Drawable drawable);
}
}CallbackImg public class CallbackImg implements ICallBack{
private ImageView imageView;
public CallbackImg(ImageView imageView){
this.imageView=imageView;
}
@Override
public void loadImage(Drawable drawable) {
imageView.setImageDrawable(drawable);
}
}
cache.clear();
}你是用什么去显示图片?ListView还是什么?有没有做它的优化?
if(imageCache.size()>20){
imageCache.clear();
System.gc();
}
imageCache.put(imageUrl, new SoftReference<Bitmap>(bmp));
}
http://www.iteye.com/topic/1118828