Master
Master

Reputation: 2959

How to change R.string.some_variable at run time?

How to change R.string.app_name at run time?

I finding out my Android app's version from manifest file. Now I want to get this string R.string.app_name from res folder. I want to append my app's version with this app_name on the run time.

Are we allowed to do so in Android?

Upvotes: 2

Views: 1017

Answers (2)

Sahil Mahajan Mj
Sahil Mahajan Mj

Reputation: 11141

One thing what you have to understand here is that, when you provide a data as a Resource, it can't be modified during run time. For example, the drawables what you have in your drawable folder can't be modified at run time. To be precise, the "res" folder can't be modified programatically.

This applies to Strings.xml also, i.e "Values" folder. If at all you want a String which has to be modified at runtime, create a separate class and have your strings placed in this Class and access during run time. This is the best solution what I have found.

If you are trying to store a value in a persistent way, take a look at SharedPreferences

Upvotes: 1

Chirag
Chirag

Reputation: 56925

No, this is not possible as all R.. resources are defined as constants in your R.java file . These are not edited by Android later on.

Upvotes: 3

Related Questions