I'm trying to save downloaded images in shared preferences in base64 format so that the app can work offline. I've used picasso
Picasso.with(mContext).load(urls.get(position)).into(imageView);
I request the server with a specific category of images and the server responds with a json containing the urls of those images. I found picasso to do this job for me as i need to write my async task for this.The images are loaded into ImageViews of a gridview image adapter.
What I want to do is that as soon as the image is loaded through the url using this function I want that bitmap image so that I can save it in shared preferences or serialize it something so that it can be used offline.
or suggest me a better solution.
Solved it!
Picasso.with(mContext)
.load(url)
.networkPolicy(NetworkPolicy.OFFLINE)
.into(imageView);
Thankyou so much guys <3
I have the user's profile pic across multiple activities in my app. Once, they change their profile image, I want to make sure that all my Glide instance's cache are cleared. That way when they navigate around the app, they can see their updated profile pic.
Currently I'm using this method: Glide.get(activity).clearDiskCache(); and that only clears the Glide cache for that activity and not across my app.
Hope someone has a quick solution, where I don't need to call the .signature() function for each glide instance in each of my activites. Or clear each glide cache in each activity.
Try
Glide.get(context).clearMemory();
OR
Glide.get(context).clearDiskCache();
Note: clearMemory() must be called on the main thread. clearDiskCache() must be called on a background thread. You can't call both at once on the same thread.
I went through this whole windmill trying Signatures and clearing caches, and to be honest - none of those options work particularly well and they're usually slow.
Glide's first recommended solution is bar far superior, although it can sometimes take a bit more time to rework your code. I eventually lost my marbles and made the necessary changes to my code. It was well worth it.
Solution: Change the image name of the image when the user uploads a new image. Get the file name and use that. Once the image URL has changed, Glide understands you have changed the image and will update the Cache accordingly.
I need to cache all images from response (currectly I am using OkHttpClient, OkHttpDownloader and Picasso classes). And caching looks like it is working.
But all images in the response have timestamp where is last update time of that image. It is possible to force picasso to re-fetch/re-load image to cache if the timestamp will be outdated? But I dont want to invalidate whole cache - just that one image.
I need pre-load images and save then to cache with additional information. Is there some easy solution?
My code for saving picture looks:
Picasso.with(mC.get()).load(image.getSrc()).fetch();
And I am searching for something like
Picasso.with(mC.get()).load(image.getSrc()).fetch().withAddInfo(image.getInfo());
With later use:
String info = Picasso.with(mC.get()).load(image.getSrc()).getAddInfo();
Is there a way?
I want to pre-fetch images using the Picasso library. In the documentation of Picasso I find the description for fetch
public void fetch():
Asynchronously fulfills the request without a ImageView or Target. This is useful when you want to warm up the cache with an image.
Note: It is safe to invoke this method from any thread.
For into(...) the behaviour is obviously that Picasso takes the image from the cache (if still available).
But what happens when I call fetch multiple times for the same image / url? Is the image re-fetched (from the network) or does Picasso find the image in the cache?