I have 3 main questions, that I couldn't find a reliable new answer.
1)does Picasso caches images automatically? Because I have seen people using okhttp3 to cache images for offline use. If yes why would they use another library to cache?
2) if your phone storage is running low, would Picasso caching system still cache it and crash the app?
3)In my app, I am using Picasso.get().fit()
. If Picasso library is caching, does it cache the whole image or only the fit version(smaller than the whole image)
And lastly, here is my code:
Picasso.get().load(downloadURL).fetch()
Picasso.get().setIndicatorsEnabled(true)
Picasso.get().load(downloadURL).fit().networkPolicy(NetworkPolicy.OFFLINE).into(viewHolder.itemView.vegetableImage,
object: Callback {
override fun onSuccess() {}
override fun onError(e: Exception?) {
Picasso.get().load(downloadURL).fit().into(viewHolder.itemView.vegetableImage)
}
})
Is network policymaking any difference at loading images or is it the same? And the fetch()
is it useful? I'm using it inside my recycler view adapter onBindViewHolder as I get my data from Firebase Database.
Thanks in advance.
1)Does Picasso caches images automatically?
Yes, it does. This is the description of the library:
A powerful image downloading and caching library for Android.
So you'll have your own cache.
Because I have seen people using okhttp3 to cache images for offline use.
There are many other libraries for that.
If yes why would they use another library to cache?
You can use Picasso or any other library but it's up to you to choose which one you feel more comfortable with.
2) if your phone storage is running low, would Picasso caching system still cache it and crash the app?
Yes, it will. This library is not checking your disk space. This operation should be done by the user. Eventually, when you have no more space left on your device and your app will try to write a new image to the disk, it will throw an exception.
3)In my app, i am using Picasso.get().fit(). If Picasso library is caching, does it cache the whole image or only the fit version(smaller than the whole image).
It will cache the image you get but there are options to transform it. You can resize the image as you like:
Picasso.get()
.load(url)
.resize(50, 50)
.centerCrop()
.into(imageView)
PS. For Android, we use also Glide:
Glide is a fast and efficient open-source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.