RhinoCan
Well-Known Member
I've been eager to add some preferences to my app for a while now and finally started looking into it the other day. Several videos into my research, one of the presenters mentioned that Android Studio has a bunch of templates which I'd never really noticed before, including a SettingsActivity template. Just out of curiousity, I clicked on that in my system and suddenly found several new items in my project, including 4 XML files and two new classes. Looking at the general_preferences.xml and comparing it to what I'd already read, I found it fairly eas to modify that file to obtain the preferences I want for my app. After the initial coding, I started tweaking as we probably all do, making it better and better. In one of my improvements, I changed the key for a couple of preferences to better names. Now my code doesn't work any more because it doesn't see the new key names.
I eventually figured out that changing my keys back to their old values worked and now my program works again. But I have to believe it is possible to change the names of preference keys *somehow*. Unfortunately, the documentation is pretty skimpy to say the least and I can think of no reasonable way to change my key names. Can anyone enlighten me on the proper technique? Do I need to abandon shared preferences and go with a named Preferences file instead that uses the key names I want? Do I have to add a second copy of the preferences I want to change so that I have the original and then a copy that is the same except for the key name? Do I have to somehow erase the shared preferences file of keys, then build it again? Do I have to find the shared preferences file on my file system and edit it manually? I vaguely remember having to do something like that back when I was writing Java for Windows and tinkered with Preferences.
I eventually figured out that changing my keys back to their old values worked and now my program works again. But I have to believe it is possible to change the names of preference keys *somehow*. Unfortunately, the documentation is pretty skimpy to say the least and I can think of no reasonable way to change my key names. Can anyone enlighten me on the proper technique? Do I need to abandon shared preferences and go with a named Preferences file instead that uses the key names I want? Do I have to add a second copy of the preferences I want to change so that I have the original and then a copy that is the same except for the key name? Do I have to somehow erase the shared preferences file of keys, then build it again? Do I have to find the shared preferences file on my file system and edit it manually? I vaguely remember having to do something like that back when I was writing Java for Windows and tinkered with Preferences.