In Android there is an conflict about how to get the best performance (like less Garbage Collector).
Fir开发者_StackOverflow中文版st, In Android best practices it recommends avoid getters and setters and also avoid creating short lived objects (like: private static final String name = "my name"). Then, what should i do with all strings that I have in my code? Should I set all of them them in the string.xml file and then get it using "this.getString(R.string.myString)" or its still good for permformance keep using "static final String name = "my name" ???
Due to the big amount of strings in my app, if I use only strings from string.xml it would be too many of "getString"s in all code, isn't that bad?
There is a slight performance overhead in calling getString()
but no extra memory overhead. And using string.xml will make managing your strings a lot easier. It also makes it much easier to localize these values if you ever choose to do so in the future.
In addition, the values in your resource files will be compiled into final static Strings
so it works out similar in the end.
精彩评论