缓存需要使用到SoftReference

step 1:定义ImageCahce

public class ImageCache{    private final HashMap> mSoftCache;    public ImageCache(Context context) {        mSoftCache = new HashMap>();    }    public Bitmap get(String url) {        final SoftReference ref = mSoftCache.get(url);        if (ref == null) {            return null;        }        Bitmap bitmap = ref.get();        if (bitmap == null) {            mSoftCache.remove(url);        }        return bitmap;    }    public void put(String url, Bitmap bitmap) {        mSoftCache.put(url, new SoftReference(bitmap));    }    private void flush() {        mSoftCache.clear();    }    }

step 2:application 中定义ImageCache成员变量

private ImageCache mImageCache;public ImageCache getImageCache() {        if (mImageCache == null) {            mImageCache = new ImageCache(this);        }        return mImageCache;    }


更多相关文章

  1. android截图代码
  2. 58. SaveVolley
  3. Android绘图API自定义View(三)
  4. Android(安卓)自定义Toast,不使用系统Toast
  5. 49 Android(安卓)fragment 自定义适配器adapter
  6. android 异步下载图片
  7. Android(安卓)自定义弹出框
  8. Android修改自定义Dialog的大小
  9. Android调用自定义Dialog中的控件

随机推荐

  1. Build your first Android(安卓)Applicat
  2. Android(安卓)PopupWindow简单使用
  3. android volley
  4. Android(安卓)ListView 知识点总结
  5. Android四大基本组件-Service详解
  6. Android(安卓)桌面未读
  7. android异步发网络请求
  8. CookieManager
  9. Android(安卓)on OMAP
  10. Android(安卓)prelink-linux-arm.map, LO