I have an app which loads images in a recyclerview. In order for it to be smooth, images are loaded using Glide. What I have noted is that the first call to Glide, for example
Glide.with(ctx).load(R.drawable.img).into(imageView)
is slower. By slower I don't mean the the loading of the image is slower, but the call itself to the method in the main thread (as if the first call would imply some initialization). I have measured it like this:
long ini = System.currentTimeMillis();
Glide.with(ctx).load(R.drawable.img).into(imageView)
Log.e(TAG, "Elapsed time: " + (System.currentTimeMillis()-ini));
The first call lasts about 30ms and from there on, it doesn't take even 1ms. It's not much, but sometimes a small lag in the UI thread is noticeable. Any guesses or workarounds on this? For now, my workaround is to load earlier a very small drawable in a background thread like this:
AsyncTask.execute(() -> Glide.with(getApplicationContext()).load(R.drawable.particle));
It works, but seems kind of ugly to me.