Snippets

cutiko SharedPreferences Memory

Updated by cutiko

File shared.java Modified

  • Ignore whitespace
  • Hide word diff
 /*Creating the SharedPreferences*/
 SharedPreferences sharedPreferencesScopeName = getSharedPreferences("SharedPreferencesStoredName", Context.MODE_PRIVATE);
 SharedPreferences.Editor editorName = sharedPreferencesScopeName.edit();
-editorName.putString("nameOfTheValueToSave", valueToSave)
+editorName.putString("nameOfTheValueToSave", valueToSave);
 editorName.commit();
 
 /*Retrieving sharedPreferences*/
 
 /*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 retriece start with lower case as in "nameOfTheValueSaved".
+**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*/
Created by cutiko

File shared.java Added

  • Ignore whitespace
  • Hide word diff
+/*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 retriece 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*/
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.