In my Android application, for example when I am inserting a Button and adding a static value for it as follows:
android:text="MY BUTTON"
It gives a warning saying Hardcoded string "MY BUTTON", should use @string resource.
I am currently trying to extend some functionality in a previously developed app; do I have to change all those statically defined values to refer to the string.xml file?
Please can anyone give an opinion on the standard? Thanks in advance.
You don’t have to fix this at all because it is a warning not an error. Your app will work perfectly well with hard-coded strings.
That said, it is advisable to fix it because it will make translating your app to other languages much easier should that ever become necessary.
Generally I try to always define strings in the
strings.xmlfile because it really doesn’t take too long when developing new code. However converting an existing project to usestrings.xmlmay be a lot of work for little gain if you are unlikely to ever need to translate your app.