androidkotlinandroid-jetpack-composeandroid-room

What's the way to keep data that will never change?


I have some data that will not change. That data is nested menu names for the entry screen of the application.

I attempted to store the data using Android Room, but it seemed unnecessary. Even if it were successful, it would be unnecessary because the data will not change.

Then I tried to store the data using a string resources array. It looked good, but I needed nested arrays, and this option was not suitable for that reason.

So in this scenario, what is the best way to keep this constant data?


Solution

  • A simple solution is just a Kotlin object:

    object Whatever {
       val yourOuterMenu = listOf(
         listOf(...),
         listOf(...),
         listOf(...)
       )
       // etc.
    }
    

    Alternatively, you could store a JSON or XML file as an asset in src/main/assets/ and read it in using AssetManager. IMHO, this only adds value if either a non-programmer needs to maintain the file or you will generate it using some tool.