static final String or strings.xml
What are the rules for using strings.xml resource files versus an interface where String constants would be defined.
I'm assuming that the strings.xml resource file would be used to define non-functional strings to be used for display purposes such as开发者_开发百科 text in various languages, date rendering formats, etc.
And Interface String constants would be used to define regular expression patterns, Intent extras variable name passing definitions, etc.
Correct. The key is that you can translate the strings in strings.xml - anything written in English (or any other language) and will be exposed to the user should be in strings.xml so you can translate it.
Patterns/regexes should be Strings for better performance, unless those regexes are language-specific.
yes, multilanguage constant in string.xml and I like to put other constants in a final class like this one:
public final class Consts {
public static final String URL = "http://www.google.com";
}
and calling them this way:
Consts.URL;
String str = getString(R.string.my_string_name);
will do the trick.
It is very convenient to store all Strings in one place (or separate XML files based on your own needs).
精彩评论