Android: constants vs. resources
When writing an Android application, what is the preferred method to store constant values, define them programatically at the beginning of a class (e.g. final int ...), or define them as resources (e.g. in abc.xml) and 开发者_如何学运维reference them when needed.
Part of my code involves a unit converter, so I want to store conversion factors and text strings for each unit. I'll only be referencing the values from a single class.
I'm looking for an answer both from a style/consistency viewpoint and a performance viewpoint.
Thanks!
Resources will be preferable it gives you support for multiple languages. Lets take an example in US they have miles as unit, but China have some thing else. So, you not need to worry for writing a code and finding out which one to display, you can create separate resources for each language and android will take care for you.
Hope this helps.
精彩评论