1,实现效果

  • 内存不足的时候使用Map集合强引用 ,不容易被释放,我使用SoftReference

 

2,实现逻辑

引用

【1】使用软引用进行,叫系统内存不足时能快点进行释放 ,软引用在版本更改后会被很快的释放

package com.utils.pic;import android.graphics.Bitmap;import android.support.v4.util.LruCache;public class MemCacheUtils {    // SoftReference<>        软引用    // WeakReference        弱引用    // PhantomReference        虚引用    // 存的是bitmap对应的软引用     HashMap> mMaps;// 存图片    public MemCacheUtils() {        super();         mMaps = new HashMap>();    }    public void setCache(String url, Bitmap bimBitmap) {        SoftReference softReference = new SoftReference(bimBitmap);          }    public Bitmap getCache(String url) {        Bitmap bitmap = null;        SoftReference softReference = mMaps.get(url);        if (softReference != null) {          // 取出bitmap         bitmap = softReference.get();        }        return bitmap;    }}

 

 

更多相关文章

  1. Android面试题总结(六)Android源码篇
  2. android http3 下篇
  3. android中.this与.class使用的区别
  4. Android(安卓)内存泄漏检查工具LeakCanary源碼浅析
  5. android 读书笔记 1
  6. android资源别名
  7. Android(安卓)NDK之 ----- Java 方法映射到C中的签名
  8. Android(安卓)点亮屏幕
  9. (笔记)Android(安卓)Gradle applicationId

随机推荐

  1. [Android] Status Bar Notifications
  2. AndroidManifest.xml 不同变量的作用(持续
  3. 利用Handler来更新android的UI (2)
  4. android 模拟器中启用相机API支持
  5. android 自定义对话框
  6. 2月11日学习日志
  7. List 去除一些默认设置
  8. android(2)
  9. Netroid:强大、快速、易用、可扩展基于Vo
  10. 使用Repo在Windows平台下載Android原始碼