Android sets String value to String.xml

Can someone help me? I want to add a String value through encoding in string.xml
I'm doing it.

String name = getResources().getString(R.string.name); if(name.lenght() < 1 ){ // getResources().setString(R.string.name);?????????????????????? } 

My string.xml is in

  <?xml version="1.0" encoding="utf-8"?> <resources> <string name="name"></string> </resources> 

Does anyone know how I can add a name value to string.xml, although encoding. Thanks!

+6
source share
5 answers

Resources are largely set in stone, so you cannot change them at runtime. If you need to keep some newlines, use SharedPreferences or SQLite .

+10
source

I don’t think you want to do this. If you are trying to keep the value constant, look at SharedPrefences . Google has a good idea about this here .

+6
source

Unable to change APK resources at runtime.

+5
source

You cannot edit these resources directly. You can look at sharedpreferences http://developer.android.com/reference/android/content/SharedPreferences.html or create your own XML file.

+4
source

You cannot edit a resource or add a resource after compiling the code. I do not know exactly what setResource does, but once your program is compiled, android builds gen files that indicate a certain amount of space for these variables, changing the variable after writing will result in memory overflow or outofbounds errors. If you want constant values ​​to try using SharedPrefs, SQL, or even your own XML stored in the application directory, which you could set up as read-only by your application.

+4
source

Source: https://habr.com/ru/post/890152/


All Articles