You can't change resource files during runtime. Strings are hard-coded in the string.xml file and hence can't be changed during runtime. Instead of trying to edit your strings.xml file, just use SharedPreferences to store the user's preferences if that's what you're trying.
You can use this code is basis for you saving and restoring values from SharedPreferences.
public class Account {
private static Account account;
private static final String ACCESS_TOKEN = "access_token";
public String accessToken;
public static Account getInstance() {
if (account == null)
account = new Account();
return account;
}
public void save(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
Editor editor = prefs.edit();
editor.putString(ACCESS_TOKEN, accessToken);
editor.commit();
}
public void restore(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
accessToken = prefs.getString(ACCESS_TOKEN, accessToken);
}
private Account() {
}
}
Now you can access your values like this. Restoring:
Account account = Account.getInstance();
account.restore(getActivity());
Toast.makeText(getActivity(), account.accessToken, Toast.LENGTH_SHORT).show();
Saving:
Account account = Account.getInstance();
account.accessToken = "newString";
account.save(getActivity());