If I were to store a string resource id in a database, could I expect the resource id to still point me to the desired string when I pull it back a few versions down the line?
Sample Case:
Store the recource Id 0x7f060003
, with the assumption it points
to the string "I'm a pleasant string!" for an inderterminate
amount of time.
Time comes along in which I need the resource, but X versions have passed, will the resource id still point to "I'm a pleasant string!"?
Use getResources().getIdentifier() instead. This way you can retrieve your ressource by its name, even if its id changes. Here's an example:
int resID = getResources().getIdentifier("nameofthedrawable", "drawable", "com.your.project");
You can then save just the name of the ressource in the database, and retrieve the ressources later from the database.
See this link for more info.
When you say X versions have passed, do you mean you have changed your source code? And updated the apk?
The R id integers are created at compile time. Therefore constant in your app once built.
However if you add a new layout / id / drawable your ID's will change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With