我已经使用内存 LRU 缓存在我的 android 应用程序中缓存位图。但是在将一些位图加载到 LRU 地图应用程序强制关闭后说内存不足异常。我已经花了一整天的时间,但还没有找到解决方案,请任何人都可以帮助我,我严重陷入了这个问题。在此先感谢。
这是我的代码
final int maxMemory = (int) (Runtime.getRuntime().maxMemory()/1024);
final int cacheSize = maxMemory / 8;
bitmapHashMap = new LruCache<String, Bitmap>(cacheSize)
{
@SuppressLint("NewApi")
@Override
protected int sizeOf(String key, Bitmap value)
{
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2)
{
return value.getByteCount()/1024;
}
else
{
return (value.getRowBytes() * value.getHeight())/1024;
}
}
};