I solved this issue by having AsyncTask
to load images from resource. And after loading from memory I store it in LRU cache. And then I retrieve it from cache.
In doInBackgroud()
I have:
BitmapFactory.Options mOptions = new BitmapFactory.Options();
mOptions.inPurgeable = true;
mOptions.inPreferredConfig = Bitmap.Config.RGB_565;
mOptions.inPreferQualityOverSpeed = false;
mOptions.inJustDecodeBounds = false;
mOptions.inScaled = true;
SoftReference<Bitmap> bm = new SoftReference<Bitmap>(
BitmapFactory.decodeResource(
getApplicationContext().getResources(), data,
mOptions));
return bm.get();
With this, I am recycling images in onDestroy()
and making Bitmap
to null.