1

I'm trying to cache images for offline use in android, as suggested on this answer: https://stackoverflow.com/a/40544554/1718174

However the problem is, I'd like to use the offline image on another subsequent activity. For example:

  • While online my first screen loads and shows a list of products with photos
  • Then I go offline. If I click on the product for a better look at the photo, the image does not load while offline (even though the image is already cached for the first activity).

If I use the example code on the first link, but on the second activity, it only shows the image when the user goes online again. Any ideas on how to achieve this? Maybe get the bytes or a bitmap from the "Glide" call?

The only working alternative I've found was to also store the image as base64, as suggested here: https://stackoverflow.com/a/22651605/1718174

But that doesn't seem to be very optimal. I have to store the same thing twice!

Community
  • 1
  • 1
Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90
  • 1
    The Firebase Storage SDK doesn't have any support for caching images offline built in. The solution is to either store the images in local storage yourself (and keep a mapping of the source location and the local file) or use an image library that support such caching, such as Glide or Picasso. If you're having problems making the latter work, share the [minimum code that reproduces the problem](http://stackoverflow.com/help/mcve). – Frank van Puffelen Jan 17 '17 at 17:21

1 Answers1

1

Use Glide to download and display images. You will never have to worry about implementing any sort of memory or disk cache. You can expect that if an image has already been loaded by Glide, and it has not been evicted from both memory of disk caches, that it will be immediately available while offline without adding any additional code.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441