Thứ Năm, 14 tháng 8, 2014
Thứ Bảy, 2 tháng 8, 2014
SparseArray instead HashMap Android example
example to getbitmap cache
Old code with HashMap
Use new SparseArray instead for better performance.
new code with SparseArray()
Old code with HashMap
Map<Integer, Bitmap> _bitmapCache = new HashMap<Integer, Bitmap>();
private void fillBitmapCache() {
_bitmapCache.put(R.drawable.icon, BitmapFactory.decodeResource(getResources(), R.drawable.icon));
_bitmapCache.put(R.drawable.abstrakt, BitmapFactory.decodeResource(getResources(), R.drawable.abstrakt));
_bitmapCache.put(R.drawable.wallpaper, BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper));
_bitmapCache.put(R.drawable.scissors, BitmapFactory.decodeResource(getResources(),
}
Bitmap bm = _bitmapCache.get(R.drawable.icon);
Use new SparseArray instead for better performance.
new code with SparseArray()