-2

I currently use many constants in my project and would like to know which is the best way to handle it. I know I could make a file Constants.java in the project, but isn't there something like constants.xml under res/values, like strings and dimen? I don't want to use them in strings.xml because that way I would restrain myself only to strings.

Andres
  • 6,080
  • 13
  • 60
  • 110
Lucas
  • 43
  • 6
  • Have a look here: http://developer.android.com/guide/topics/resources/more-resources.html. You can define them in `values.xml` and they are not necessarily strings – Andres Jul 15 '14 at 16:09
  • how is your question related to AndroidStudio? – Blackbelt Jul 15 '14 at 16:09
  • Strings.xml is for UI strings that could be translated into different languages. Don't put constants there. – Kevin Krumwiede Jul 15 '14 at 17:22
  • Consider using enum constants where appropriate. http://stackoverflow.com/questions/4709175/what-are-enums-and-why-are-they-useful/4709224#4709224 – Kevin Krumwiede Jul 15 '14 at 17:24

1 Answers1

0

If I understand your question correctly, you want somewhat of a "master file" that will hold more than just what the individual files (colors,strings,dimen,etc,etc) can do on their own.

In short, there isn't one file that can hold everything. If you take a look at the link Andres posted (here) it is possible to add other resources, but they must be one of those predefined types.

Other than that, you'll need a separate class to handle that. Generally speaking, you probably wouldn't want anything more complicated than what is available as a constant (i.e. you likely would only want primitives types like ints and doubles OR Strings).

KyleCrowley
  • 900
  • 6
  • 14
  • 31