বাংলায় অ্যান্ড্রয়েড সহায়িকা - Bangla Android Guide

পরবর্তী ব্যবহারের জন্য একটি বিটম্যাপ সেভ করা

নি¤েœাক্ত খন্ডচিত্রটি দেখায় যে স্যাম্পল অ্যাপে পরবর্তীতে সম্ভাব্য ব্যবহারের জন্য কীভাবে একটি বিটম্যাপ স্টোর হয়। যখন একটি বিটম্যাপ অ্যান্ড্রয়েড ৩.০ বা এর চেয়ে উপরের লেভেলে রান করে এবং একটি বিটম্যাপ LruCache থেকে উচ্ছেদ হয়, বিটম্যাপের প্রতি একটি সফট রেফারেন্স একটি HashSet এর মধ্যে স্থাপিত হয়, inBitmap সহকারে পরবর্তীতে সম্ভাব্য ব্যবহারের জন্য:

Set<SoftReference<Bitmap>> mReusableBitmaps;
private LruCache<String, BitmapDrawable> mMemoryCache;

// If you're running on Honeycomb or newer, create a
// synchronized HashSet of references to reusable bitmaps.
if (Utils.hasHoneycomb()) {
    mReusableBitmaps =
            Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
}

mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) {

    // Notify the removed entry that is no longer being cached.
    @Override
    protected void entryRemoved(boolean evicted, String key,
            BitmapDrawable oldValue, BitmapDrawable newValue) {
        if (RecyclingBitmapDrawable.class.isInstance(oldValue)) {
            // The removed entry is a recycling drawable, so notify it
            // that it has been removed from the memory cache.
            ((RecyclingBitmapDrawable) oldValue).setIsCached(false);
        } else {
            // The removed entry is a standard BitmapDrawable.
            if (Utils.hasHoneycomb()) {
                // We're running on Honeycomb or later, so add the bitmap
                // to a SoftReference set for possible use with inBitmap later.
                mReusableBitmaps.add
                        (new SoftReference<Bitmap>(oldValue.getBitmap()));
            }
        }
    }
....
}