Snippets

cutiko SharedPreferences Memory

Created by cutiko last modified
/*Creating the SharedPreferences*/
SharedPreferences sharedPreferencesScopeName = getSharedPreferences("SharedPreferencesStoredName", Context.MODE_PRIVATE);
SharedPreferences.Editor editorName = sharedPreferencesScopeName.edit();
editorName.putString("nameOfTheValueToSave", valueToSave);
editorName.commit();

/*Retrieving sharedPreferences*/
SharedPreferences sharedPreferencesScopeName = getSharedPreferences("SharedPreferencesStoredName", Context.MODE_PRIVATE);
String dataTypeName = sharedPreferencesScopeName.getString("nameOfTheValueSaved", "Default datatype in case memory is empty");

/*Note*/
/*My naming convention is for the SharedPreferences where the datatype is going to be stored start with upper case as in "SharedPreferencesStoredName"
**and for the data type name later to be retrieve start with lower case as in "nameOfTheValueSaved".
**Also, the default data type can be null or "" (empty string), so check if there is anything or not.
**If there is nothing then the defaul will be "" or null*/

Comments (0)