what is the best way to access and store android preference keys?
I don’t want to always enter them manually beacuse then I can’t change them quickly.
At the moment I only see two possibilities:
-
final static key_xxx
but they can’t be referred in the preference.xml -
put the keys in the strings.xml
but then they may be translatet, and that too is not what I want.
Are there any more possibilities of storing preference keys?
The first solution is the most common one. Yes, they can’t be automatically referred to in the preferences file, but at least the keys will be consistent throughout your code. If you need to change a key at some point then yes, you will have to account for that and copy the value from the old key if needed. However, you will rarely change keys (if at all).
From my experience, the only time you want to change a key is if its behavior changes (e.g. the possible values it can have). I usually change the key’s name when I want to ignore whatever value was set in there and start from scratch. So you can look at the fact that the preference file doesn’t store the reference to the key name as a feature, not a bug :).