Anders Anders - 7 months ago 73
Java Question

Using Glide, ArrayLists repeats itself in a ViewPager?

I am using Glide to load the images from

Drawable
s into a Fragment containing
ViewPager
, everything works smooth but when I install the Application over again and again then the List of images start to repeat 2, 3 times in
ViewPager
i.e after last page of
ArrayList
it will start from first again for like 2, 3 times and repeat the list, and if i clear the application data by going to
Settings>Apps
then it gets fine, I tried skipping the
DiskMemory
but its still same.

Not important but here is the part of my
PagerAdapter
:

Glide.with(mContext)
.load((Integer) data.get(position))
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(mImageView);


What is the best approach to solve this issue? clearing cache on exit? or skipping both memory and disk cache?

Number of images is really large about 700, but size of images is not much i.e around 30kb to 50kb.

Answer

For anyone else having the same issue.

The drawable IDs may change on each compile, that's why we have the R class, and I was testing my debug build, and version code doesn't change between builds.

Glide uses VersionCodeSignature (see load(int) sources) to make sure what I experienced doesn't happen in real life, because Play Store forces you to change the version on each release.

So when we change the VersionCode Glide doesn't use the old cache and creates new cache for new build.

Hope it helps someone