Android examples for App:Cache
get Bitmap From Mem Cache LruCache
//package com.book2s; import android.graphics.Bitmap; import android.support.v4.util.LruCache; public class Main { private static LruCache<String, Bitmap> mMemoryCache; public static Bitmap getBitmapFromMemCache(String key) { if (mMemoryCache == null) initMemoryCache();//from ww w.j a va2s . co m return mMemoryCache.get(key); } private static void initMemoryCache() { if (mMemoryCache == null) { int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); int cacheSize = maxMemory / 2; mMemoryCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap bitmap) { return bitmap.getRowBytes() * bitmap.getHeight() / 1024; } }; } } }