//Saving SharedPreferences prefs = getSharedPreferences("YourPreferencesName", 0); prefs.edit().putString("KeyValue", actual_variable); prefs.commit(); //Retrieving data String str = prefs.getString("YourPreferencesName", "DefaultValueIfPrefNotFound");
SharedPreferences prefs = getSharedPreferences("MySharedPreferences", Activity.MODE_PRIVATE); SharedPreferences.Editor preferences = prefs.edit(); String firstString = prefs.getString("MyFirstString"); //check if firstString has changed on the server //for example, set a new String that you retrieve from the server to firstStringMaybe if (firstString != firstStringMaybe) { //meaning you need to update firstString prefs.putString("MyFirstString", firstStringMaybe); prefs.commit(); }
SharedPreferences sp = ActivityA.this.getSharedPreferences("prefs", MODE_PRIVATE); SharedPreferences.Editor preferencesEditor = sp.edit(); sp.putBoolean("from" , true); sp.commit();
String inputName = "Peter"; String inputPassword = "I love Stackoverflow"; SharedPreferences prefs = getSharedPreferences("myPrefs", 0); SharedPreferences editor = prefs.edit(); editor.putString("accountName", inputName); editor.putString("accountPassword", inputPassword); editor.commit();
String inputName = "Peter"; String inputPassword = "I love Stackoverflow"; SharedPreferences prefs = getSharedPreferences("myPrefs", 0); SharedPreferences editor = prefs.edit(); editor.putString("accountName", inputName); editor.putString("accountPassword", inputPassword); editor.commit();
appPreferences.commit();
sharedPref.commit();
//Determine the String values SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); Int numberOfEvents = preferences.getInt("numberofevents", 0); numberOfEvents++; preferences.putString("title" + numberOfEvents, titleVariable); preferences.putString("description" + numberOfEvents, descriptionVariable); preferences.putInt("numberofevents", numberOfEvents); preferences.commit();