Answers for "sharedpref android"

6

android sharedpreferences

// load file
SharedPreferences sharedPref = getSharedPreferences(PREFERENCES_FILENAME, MODE_PRIVATE);

// read value
String value = sharedPref.getString(PREFERENCE_KEY, null);

// write value
sharedPref.edit()
  .putString(PREFERENCE_KEY, value)
  .apply();
Posted by: Guest on April-19-2021
1

android save int

public void saveInt(int val, String key){
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(key, val);
    editor.apply();
}

public int getInt(String key){
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
    int val = prefs.getInt(key, 0);
    return val;
}
Posted by: Guest on September-20-2020
4

android sharedpreferences

SharedPreferences sharedPref = getSharedPreferences("name", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("key", "Value");
editor.commit();
Posted by: Guest on November-07-2020

Code answers related to "sharedpref android"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language