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?
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.
2
Android studio provides an opportunity for working with XML files. Example of file:
<parent_element>
<element1>
<nested_element_1>Some data</nested_element_1>
<nested_element_2>Some other data</nested_element_2>
</element1>
<element2>
<nested_element_3>Some data</nested_element_3>
<nested_element_4>Some other data</nested_element_4>
</element2>
</parent_element>