14

I know we can use resource strings to store values, but is it possible to change those values at run time?

For example, I added two new resource elements username and password, and I want to change these values at run time. Or is there an alternate way to store values?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
BreakHead
  • 10,480
  • 36
  • 112
  • 165
  • Possible duplicate of [Change value of R.string programically](http://stackoverflow.com/questions/9674925/change-value-of-r-string-programically) – Suragch Sep 07 '16 at 04:56

2 Answers2

19

String resources are absolutely static defined; you can't change their values. Use SharedPreference which is to store your data, and you can change, update or do whatever to suit your needs.

Here is a sample for using SharedPreference: How to use SharedPreferences in Android to store, fetch and edit values

Community
  • 1
  • 1
Pete Houston
  • 14,931
  • 6
  • 47
  • 60
2

strings.xml are for constant strings only. Their values can change automatically when the phone language changes provided that you have created several strings.xml files such as strings-us.xml, strings-fr.xml.

You can store username & password values in Preferences. They will be stored permanently with your application.

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158