使用软引用SoftReference 内存缓存

1
2
// 第一中缓存图片的方式 通过内存来缓存
    Map<String, SoftReference<Bitmap>> iconCache;
1
2
// 初始化内存缓存
        iconCache = new HashMap<String, SoftReference<Bitmap>>();
1
2
3
4
5
6
7
8
9
10
11
// 以下第一种加载图片的方式
  
            /*
             * if (iconCache.containsKey(imagePath)) { SoftReference<Bitmap>
             * reference = iconCache.get(imagePath); if (reference != null) {
             * Bitmap bitmap = reference.get(); book_img.setImageBitmap(bitmap);
             
             * } else { loadingImage(imagePath); }
             
             * } else { loadingImage(imagePath); }
             */
1
2
3
4
/*
                             * // 加载图片到内存中 iconCache.put(imagePath, new
                             * SoftReference<Bitmap>( bitmap));
                             */

 

 

 

 

 

 

 

 

 



来自为知笔记(Wiz)


posted on 2014-04-28 13:54  转折点人生  阅读(398)  评论(0)    收藏  举报