klefevre klefevre - 9 months ago 52
Android Question

Where to store global constants in an Android application?

I would know what is the best practice for storing global constants which can change with the environnement (debug, preprod, prod, release, etc) at compile time.

In iOS, I used to keep all global constants in a header file and change it with pre-processor macro see this answer:

Where to store global constants in an iOS application?

What solution should I use for Android ?

Answer Source

Create a class constants in your base package folder.

(or create an interface instead of a class so there is no need to reference the class everytime, however this is bad practice due to code readability, but it will work)

Fill it with public static final values.

Moreover, both the class as well as the interface can also be declared as abstract.