网上的方法都处理过了,感觉还是解决不了。
效果是有一点,只是能翻多几页,最终还是发生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 为参数软引用,
因代码太多所以只给出主要的图片读取代码

解决方案 »

  1.   

    option都试过了,这问题困了好几天,网上方法基本都试过。
      

  2.   

    本质是就是内存不够用,要不加大可用内存,要不及时回收。1,新版本用(具体哪个哪个版本之后忘了)xml中的android:largeHeap。2, 想办法把android加载进来的系统res弄掉(如果你没用到),这个大概占了4M多,我反正一直想弄掉一直不知道怎么弄3,回收啊回收,这里的一个问题是加载新图片进来时会卡(I/O啊、解码啊、重新填充缓存啊什么的),没什么好办法,根据你要展现的业务和预估的用户行为来选择相应策略吧。另外一个办法是两个Activity跑在不同的进程中,这样就有双份内存可用(Android内存限制是每个进程16M/24M),类似双缓冲。4,牺牲图片质量,其实就是降低色深。5,开启硬件加速,同样要新版本,这个只能增加流畅,无法解决OOM。用OpenGL ES做texture blt,其实也一样-_-