Answer the question
In order to leave comments, you need to log in
Why can't I load a picture into the cache (Picasso)?
In RecyclerView, you need to load images along the paths that are stored in the database. When loading large images (3000 * 4000), the list is initialized with lags. To avoid this, I decided to try loading images from the cache using the following. the code:
LruCache cache = new LruCache(contex);
if (cache.get(imgPath) != null)
{
//Если картинка есть в кэше
holder.image.setImageBitmap(cache.get(imgPath));
Log.d("Picture ", "Picture is in cache");
}
else
{
try
{
//если картинки нету в кэше
Picasso.get().load(new File(imgPath).getAbsoluteFile()).into(holder.image);
cache.set(imgPath, BitmapFactory.decodeFile(new File(imgPath).getAbsolutePath()));
Log.d("Picture ", "Picture is not in cache");
}
catch (java.lang.NullPointerException e)
{
Log.d("Picture", "Failed to load picture from this path");
Log.d("Picture", "cache size: " + cache.size());
}
}
Answer the question
In order to leave comments, you need to log in
No need for this perversion. Picasso should have its own cache, use it. If it is not there, change the picassa to glide.
And, in any case, 3k x 4k pictures are a tin. Glyde will resize them on the go.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question