i have the following code to cache bitmaps , when i try to retrieve them using their key . They always return null . Please help me . Thank You
final int memClass = ((ActivityManager) mcontext.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
final int cacheSize = 1024 * 1024 *memClass ;
Toast.makeText(mcontext,"Max Cache "+cacheSize,Toast.LENGTH_LONG).show();
mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protected int sizeOf(String key, Bitmap bitmap) {
// The cache size will be measured in kilobytes rather than
// number of items.
return bitmap.getByteCount() / 1024;
}
};
Functions to get and set cache
public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
if (getBitmapFromMemCache(key) == null) {
Toast.makeText(mcontext,"CEO "+key+" - "+bitmap,Toast.LENGTH_LONG).show();
mMemoryCache.put(key, bitmap);
}
else
{
Toast.makeText(mcontext,"NULL",Toast.LENGTH_LONG).show();
}
}
public Bitmap getBitmapFromMemCache(String key) {
return mMemoryCache.get(key);
}
-----------UPDATE----------------------------------------- Well after some debugging found out that it is inserting the value , but i cannot access it after i have exited the app. When i try to relaunch the app the cache is lost. Please could someone help me how to retain that value . Thank You