Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need someone review my sharedPreference class , which better to create sharedpreference with constant name MyPREFERENCES like this , or like they I do in class

SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);    

Editor editor = sharedpreferences.edit();
editor.putString("key", "value");
editor.commit(); 

my class

public class SharedPreferencesManager {

        private Context context;
        private SharedPreferences prefs;

        public SharedPreferencesManager(Context context) {
            this.context = context;
        }

        public void writeIntoPreferences(String[] names, String[] values) {
            Editor editor = getSharedPreferences().edit();
            for (int i = 0; i < names.length; i++) {
                editor.putString(names[i], values[i]);
            }
            editor.commit();
        }

        public String readPreference(String name, String defaultValue) {
            return getSharedPreferences().getString(name, defaultValue);
        }

        public void clearPreference(String[] names) {
            Editor editor = getSharedPreferences().edit();
            for (int i = 0; i < names.length; i++) {
                editor.putString(names[i], "");
            }
            editor.commit();
        }

        public void clearAll() {
            Editor editor = getSharedPreferences().edit();
            editor.clear();
            editor.commit();
        }

        private SharedPreferences getSharedPreferences() {
            if (prefs == null) {
                prefs = context.getSharedPreferences(Constants.PREFERENCES, Context.MODE_PRIVATE);
            }
            return prefs;
        }
    }
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.