Pages

Tuesday, June 2, 2015

SharedPreferences

        static SharedPreferences.Editor editor;
static SharedPreferences sharedpreferences;
public static final String MyPREFERENCES = "MyPrefs" ;

public static void SaveData(Context c,String KEY,String Value){

sharedpreferences = c.getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
editor = sharedpreferences.edit();
editor.putString(KEY,Value);
editor.commit();


}

public static String getData(Context c,String KEY,String FIX){

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

return sharedpreferences.getString(KEY, FIX);
}

public static void clearData(Context c,String KEY){
sharedpreferences = c.getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
editor = sharedpreferences.edit();
editor.remove(KEY);
editor.commit();


}
public static void clearAllData(Context c){
sharedpreferences = c.getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
editor = sharedpreferences.edit();
editor.clear();
editor.commit();


}

No comments:

Post a Comment