Loading different images from cache using Glide Library - android

i am retrieving images URL using volley from MySQL Database , when am online i have no problem , but i need to make it offline too so am using SQLite to store data, but when the image loads it displays the first picture saved in cache , and i have no idea how to resolve this.
I was using BLOB before but the application became too slow after adding lot of data.
Thanks for help.

Use signature
Glide.with(this)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.signature(new StringSignature(UUID.randomUUID().toString())) //use this
.into(imgView);

Related

Glide get image cache list

here the scenario
1: Open android app with glide, then glide download the image and save it in cache.
2.if app is close then reopen, then the URL is same, glide load the image from cache
3:While not connecting to internet,when open the app, i want to make glide display random image from cache, it will be nice if glide can list all the URL from cache
how to make step 3 work?
You can use DiskCacheStrategy.
Set of available caching strategies for media.
static DiskCacheStrategy ALL
Glide uses memory and disk caching by default to avoid unnecessary
network requests.
Glide.with(contextOBJ)
.load("IMAGE_LINK")
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageViewOBJ);

Android Glide doesn't get the newest version of the picture

Trying to work with Glide for Android and Firebase.
My code is working perfectly (uploading, downloading into ImageViews), my problem is that when I change the image in the Firebase Storage (for example, a user image), the app doesn't "know" that the image in the database has changed and keeps showing the cached version.
Obviously I want the app to use cache, but in a way that knows if the original image has changed in the database.
Is there a way to do it?
if cache is not wanted, you can try
Glide.with(ctx)
.load(Uri))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(mImage);
And also This will remove cache memory which is stored by Glide.
Glide.get(ctx).clearDiskCache();

How to load image from same url using glide or picasso in android?

Hi I have an wired issues stopping my development. I am working on the application similar to facebook having posts, comments likes and chat functionalities. In each functionality I need to load the user's profile picture. I can able to load the profile pictures when I was trying to login for the first time using glide libary. But when users changes the profile picture server is returning the same url but different image. How to invalidate or load image when it was updated and what are the best ways to handle this scenario?
Your answers are valuable to me. Thanks in advance.
like this:
Glide.with(MainActivity.this)
.load("URL")
.asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(R.drawable.man_default)
.into(imgUserImage);
For Picasso you can use both MemoryPolicy and NetworkPolicy
Picasso
.with(context)
.load(url)
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.networkPolicy(NetworkPolicy.NO_CACHE)
.into(imageViewFromNetwork);
refer this its well explained here!
I think disabling cache strategy will be helpful for you as your url is same so
DiskCacheStrategy.NONE
From Here
difference between the enum parameters for the .diskCacheStrategy() method:
DiskCacheStrategy.NONE caches nothing, as discussed
DiskCacheStrategy.SOURCE caches only the original full-resolution image. In our example above that would be the 1000x1000 pixel one
DiskCacheStrategy.RESULT caches only the final image, after reducing the resolution (and possibly transformations) (default behavior)
DiskCacheStrategy.ALL caches all versions of the image
try using:
Glide.with(context)
.load(url)
.placeholder(R.drawable.ic_profile)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(ivUserProfilePhoto);
here is a relevant Question
I am glad to give you suggestion over it.
First, you should remember every profile has unique URL and it should be immutable on the server.
These issue is more sort of on server side because you never know on client side when other users changed their profile pictures but server knows.
Probable solution we have done for it
Whenever any user changes in profile picture we saving these picture on server with his timestamp and it attached to it's URL.
eg : http://image.pngtimestamp=1336t78387
So, now you have different URL for the user profile you don't have to change it on client side.
Only thing you have to take care for it is how you will get these updated URL for the specific user.We are requesting for URL to server whenever we chat with other user or see his profile. so every time we get the latest pic.
Even you want to improve performance for it you can request for updated images URL at the start of your application when user launch app so server can return you all the images after given timestamp.
Hope these helps you.

Android Image fetching library

Hi i wanted to know is their any library in which we pass the URL and the image-view and it checks whether the images is present on device if not, then fetch image from URL and store to device and bind with the view passed. I tried writing the code but once the view is loaded and image is not fetched the images is never fetched in future unless i uninstall the app , i also tried universal image loader library and asynchronous image loader
Picasso is doing all things what you want.
It loads from internet and cache
It loads from cache
It loads from Local File
Read More Here And Here
Try volley library. you have a NetworkImageView I guess. Which fits your need.

Storing images from api into room db

I want to know the best way to store images from and api into room db. I'm making a sport application where I receive data and images from an api. When I'm in online mode, the images are loaded using the urls provided by the api but when offline, images should be stored and retrieved from the database in offline mode. I want to know how to convert that url of image to an image and load it in offline mode.
PS : more than 100 images will be saved, does room db fit with that? Thank you.
store your image in cache using picasso
first add this to your gradle.
implementation 'com.squareup.picasso:picasso:2.71828'
then you can call the image from your url and store it in your cache.
Picasso.get().load(YOUR_IMAGE_URL).error(R.drawable.error_img).placeholder(R.drawable.loading_image).into(YOUR_IMAGEVIEW);
Picasso will only download the image once, and if you call the same url again it will be redirected to your cache instead of downloading it again(more or less).
note: check the profilier to see the data consumption.
To continue with L2_Paver's answer.
You can also check Glide for the same purpose. You might want to consider the pros and cons of each libraries which serves well for your purpose. This answer might give you some more insights about the comparison.
Picasso v/s Imageloader v/s Fresco vs Glide

Categories

Resources