android set/get preference value

www.la‮iruttu‬.com
android set/get preference value
boolean mBoolean = PreferenceManager.getDefaultSharedPreferences(yourContext).getBoolean(key, defaultValue); 
//getBoolean will return defaultValue is key isn't found

//you can also use getInt, getFloat, getLong, getString, getStringSet and change the variable type, of course

boolean committed = PreferenceManager.getDefaultSharedPreferences(yourContext).edit().putBoolean(key, mValue).commit();

//you can also use putInt, putFloat, putLong, putString, putStringSet and change the value of mValue
//committed is true if everything went alright, false if there was an error
Created Time:2017-09-06 23:19:12  Author:lautturi