Does Android cache image sources from URLs?


#1

I’m developing an app which allows users to change their profile picture. On the home page, the image source URL for the user’s profile picture is set upon navigating onto the page and the source URL is simply the user’s unique ID ending with “.jpg”. When users update their profile picture, the old profile picture is overwritten and replaced with the new profile picture.

The problem arises when I try to refresh the page and show the new profile picture. On iOS, navigating away and back to the page after changing the profile picture will cause the new profile picture to appear. However, repeating the same steps on Android will not change the profile picture; instead, the old profile picture will persist. From this, I have two questions:

  1. Does Android cache image sources from URLs? My theory is that Android isn’t “grabbing” the new image because the two images share the same source URL, so it uses a cached image source instead of the updated source. I saw this article which says that “To prevent that scenario, in NativeScript 2.5.x and above using the src property in Android will internally load the Bitmap in Java.”, but wasn’t sure if this applied to my issue.

  2. How can I solve this issue? Assuming that my theory is correct (Android isn’t “grabbing” the new image because the two images share the same source URL), my current idea is to add another unique string to the photo URL such that, instead of using the same URL for both the previous and updated image, Android will grab the image source for the updated image since they now have different source URLs. However, this would require me to change how I grab profile pictures throughout my app; is there a way to either disable or clear the supposed Android cache?

EDIT: I got around this by adding a randomly generated query string at the end of my image source URL, but if anyone can shed some light on why this happened in the first place, I’d really appreciate it.


#2

By default images are cached in Android until you set useCache property of Image to false.


#3

Thanks @manojdcoder, I didn’t know that was a property. Is that documented in the API? I couldn’t find anything in this page.


#4

It’s documented and of course highlighted too here, I believe you came through that.


#5

Hmm I couldn’t find it on the docs for Image nor Image Module, but I found the relevant passage in the article I looked at before. Sorry for the hassle, thanks again!