2

I am developing an app where I need to cache images such that I can retrieve them when the user is offline and they should also be accessible once the user closes and reopens the app.

I need something like

FirebaseFirestoreSettings.setPersistenceEnables(true)

My problem is that I can not find a proper way of doing it.

  • I tried saving the pictures to LruCache but all the cached data gets deleted once the app is closed.
  • I can save the pictures into a file and retrieve them but I don't want the user to have access to those pictures as some of them might be copyrighted.
  • I could store the Bitmaps using DiskLruCache but I cannot find a tutorial explaining how it works and the article about it on the android developer site is not of any help.

Maybe `Glide is a solution but I could not retrieve the saved bitmap when I needed it.

Is there a correct or best way of doing it?

Zoe
  • 27,060
  • 21
  • 118
  • 148
TheBatz
  • 115
  • 2
  • 12
  • You may use this tutorial https://developer.android.com/topic/performance/graphics/cache-bitmap – Rasheed Jan 17 '19 at 11:50
  • @DawidJ Please read [When should code formatting be used for non-code text](https://meta.stackoverflow.com/a/254995/6296561) – Zoe Mar 24 '19 at 13:26

2 Answers2

1

Try Picasso, it has an automatic image caching.

0

I don't fully understand the idea of downloading images by user, caching them but not allowing to display them later.

You have 2 options here in my opinion.

First one is to use Glide cache but you dont have full control of when and how images will be cleared.

Second option is to save images as files in private directory (user won't be able to preview this images) and create some kind of logic in application (based on your restrictions) to control when and how to display those images to users in app.

DawidJ
  • 1,245
  • 12
  • 19