“Android SharedPreferences” Respostas de código

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

Obtenha valor de preferência 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

Armazene dados no Android SharedPreferences

// 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

Definir valor de preferência 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

Respostas semelhantes a “Android SharedPreferences”

Perguntas semelhantes a “Android SharedPreferences”

Mais respostas relacionadas para “Android SharedPreferences” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código