“Android SharedPreferences” Kod odpowiedzi

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();
Merlin4 (ranken)

Android SharedPreferences

SharedPreferences sharedPref = getSharedPreferences("name", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("key", "Value");
editor.commit();
Jesus

Uzyskaj wartość preferencji Android

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
Fedeboss

przechowuj dane w sharedPreferences Android

// MY_PREFS_NAME - a static String variable like: 
//public static final String MY_PREFS_NAME = "MyPrefsFile";
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
 editor.putString("name", "Elena");
 editor.putInt("idName", 12);
 editor.apply();
Confused Camel

Ustaw wartość preferencji Android

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
Fedeboss

Odpowiedzi podobne do “Android SharedPreferences”

Pytania podobne do “Android SharedPreferences”

Więcej pokrewnych odpowiedzi na “Android SharedPreferences” w Java

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu