Need for in-memory Data Storage Solution for Android

50 Views Asked by At

I need to have API response data centrally stored so that I can access it from any Activity/Fragment/Composable/Viewmodel.

  1. I've tried using Kotlin Singleton Objects but for some reason, it gets garbage collected or something, and the data gets lost.

  2. I've checked Room DB but since I don't need the data to persist after the app got killed, I think this is an overkill.

  3. Using Preference will be expensive due to the constant string<->object conversions.

1

There are 1 best solutions below

0
On

Haven't used Kotlin for a while but in JAVA I just use a class with a static reference for such tasks. I create the class instance at the beginnig and asign the reference. This never gets garbage collected.