Letme / give-me-coinsMonitoringApp

Android app for monitoring workers on give-me-coins.com mining pool.
GNU General Public License v3.0
24 stars 21 forks source link

Storing SharedPreferences keys in strings.xml can lead to problems #22

Open justinmuller opened 10 years ago

justinmuller commented 10 years ago

Defining the keys of SharedPreferences in string resource files, such as this is problematic for a couple of reasons:

1) A string value may be updated in strings.xml to change the text on the UI, inadvertently breaking the retrieval of previously specified preferences. For example, if the text "Show LTC" were changed to "Update LTC" then the previously specified preference would not be loaded because the call here would resolve to sharedPref.getBoolean("Update LTC") instead of sharedPref.getBoolean("Show LTC")

2) This pattern does not aid multi-language support. For example, if a French user (with their device locale set to fr) begins using the app today, their LTC preference is set via editor.putBoolean("Show LTC", boolean). If we later include French translations (someone contributes res/values-fr/strings.xml) and push out an update, the updated code will attempt to retrieve that preference via sharedPref.getBoolean("Afficher LTC"). Thus, after an update it might looks like the preferences where lost to a user with a non-English locale.

One possible solutions is to hardcode the keys in the code (or introduce constants)

Letme commented 10 years ago

I must admit I did not predict a multi-language support, but what you claim sure presents a valid suggestion (in case we would want to change language in-app and on fly).

HaigB commented 8 years ago

give-me-coinsMonitoringApp/src/give_me_coins/dashboard/GMCPoolService.java