According to this answer in SOEN , what you want is not possible - string.xml
is actually only- reading. The recommended alternative is to use SharedPreferences
: a means to create and persist user preference data .
This link has an example of how to use them (if this alternative really catches you, of course):
public class Calc extends Activity {
public static final String PREFS_NAME = "MyPrefsFile";
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
. . .
// Recupera as preferências salvas
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean silent = settings.getBoolean("silentMode", false);
setSilent(silent);
}
@Override
protected void onStop(){
super.onStop();
// Atribui uma nova preferência; isso é feito através de um Editor
// Todos os objetos são de android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("silentMode", mSilentMode);
// Confirma as edições
editor.commit();
}
}