网上的方法都处理过了,感觉还是解决不了。
效果是有一点,只是能翻多几页,最终还是发生OOM.
我的处理逻辑是图片首次从网络上加载,然后保存到SD卡,用到图片处先判断是否存在SD卡中,若存在能读SD卡
主要代码:
String fileName = LswSetting.SDPATHIMG+ lswAndroidHelper.getMd5FileName(filename)+".jpg";
if(lswAndroidHelper.isImgInSDCard(fileName))
{
try
{
Input input = fileHelper.readSDFile(fileName);
bitmapImage = BitmapFactory.decodeStream(input, null, options);
bitmapList.add(bitmapImage);
}
catch(Exception ex)
{
}
}
else
{
try{
URL url = new URL(filename);
URLConnection conn = url.openConnection();
conn.connect();
InputStream in = conn.getInputStream();
buf= new BufferedInputStream(in);
//bitmapImage = BitmapFactory.decodeStream(buf);
bitmapImage=BitmapFactory.decodeStream(in, null, options);
bitmapList.add(bitmapImage);
//不加内存缓存
this.addCacheBitmap(bitmapImage, filename);
//lswAndroidHelper.saveBitmapToFile(bitmapImage, fileName);
}
catch(Exception ex)
{
} addCacheBitmap 为参数软引用,
因代码太多所以只给出主要的图片读取代码
效果是有一点,只是能翻多几页,最终还是发生OOM.
我的处理逻辑是图片首次从网络上加载,然后保存到SD卡,用到图片处先判断是否存在SD卡中,若存在能读SD卡
主要代码:
String fileName = LswSetting.SDPATHIMG+ lswAndroidHelper.getMd5FileName(filename)+".jpg";
if(lswAndroidHelper.isImgInSDCard(fileName))
{
try
{
Input input = fileHelper.readSDFile(fileName);
bitmapImage = BitmapFactory.decodeStream(input, null, options);
bitmapList.add(bitmapImage);
}
catch(Exception ex)
{
}
}
else
{
try{
URL url = new URL(filename);
URLConnection conn = url.openConnection();
conn.connect();
InputStream in = conn.getInputStream();
buf= new BufferedInputStream(in);
//bitmapImage = BitmapFactory.decodeStream(buf);
bitmapImage=BitmapFactory.decodeStream(in, null, options);
bitmapList.add(bitmapImage);
//不加内存缓存
this.addCacheBitmap(bitmapImage, filename);
//lswAndroidHelper.saveBitmapToFile(bitmapImage, fileName);
}
catch(Exception ex)
{
} addCacheBitmap 为参数软引用,
因代码太多所以只给出主要的图片读取代码
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货