1

Is the value of R.id.akey immutable if I store it and compare to R.id.akey?

I do store the value from the generated R.id.* from ids.xml into SharedPreferences to compare later

<resources>
    <item name="opt_1" type="id" />
    <item name="opt_2" type="id" />
</resources>

prefs.edit().putInt("PREF", R.id.opt_1).apply()

is safe to assume that the generated value will be equals between building project?

prefs.getInt("PREF", -1) == R.id.opt_1

Sorry for a yes or no question PS: Pretty sure this ins`t a problem for compile time

I noticed and its does change values if you modify ids.xml, there's how to make it immutable without using final static ints?

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • 1
    AFAIK, resource IDs still can change between builds, particularly as you add/remove resources. – CommonsWare Mar 24 '20 at 19:05
  • ```it is simply a unique ID that you can attach to other resources or use as a unique integer in your application.``` but I do have a problem that looks like this – Marcos Vasconcelos Mar 24 '20 at 19:10
  • 1
    It is unique per build. https://stackoverflow.com/a/6646113/2754562. ```Note that aapt by default makes no attempt to keep these identifiers the same between builds. Each time the resources change, they can all get new identifiers. ``` So it is unsafe – aiqency Mar 24 '20 at 20:03

0 Answers0