Using Static Methods to handle a large list of SharedPrefs... Is this a good idea?
I am writing a game for Android that requires a ton of simple data (stats, map locations etc...) to be stored in SharedPreferences.
开发者_StackOverflow社区To simplify and streamline this process I created a Settings class that uses static set and get methods for all the sharedprefs. Then I simply call settings.getXYZ() from anywhere else in the app.
Lately I have read that using static methods in Android is a bad idea in the long run. Is there a better way to accomplish this?
I would recommend you have a set of static methods in a public class designed to get and set any preferences as properties.
This is how I have it setup in my apps, and it works great! As long as you treat them as static objects, you should have no issues.
For a big set of values to be stored I suggest you to use a sqlite db instead of sharedpreferences. It is easier to manage and not difficult to learn to use it.
精彩评论