Jan Groth
Jan Groth

Reputation: 14636

Keeping external application configuration centralized in Android

(Android-Noob)

I can't find a best approach for encapsulating configuration resources.

Basically I'd like to keep configuration values like these:

<string name="environment">dev</string> 
<integer name="lookup_timeout">750</integer> 
<boolean name="use_cache">true</boolean>

Anything I'm missing?

Update: What are configuration resources?

A set of values that typically is environment specific and will most probably change / being fine-tuned by the developer during application development. It is certainly not user-modifiable, and though has nothing to do with user-preferences.

Typical examples are:

C'mon, you must know what I mean ;-)

Upvotes: 0

Views: 182

Answers (2)

CommonsWare
CommonsWare

Reputation: 1006614

A set of values that typically is environment specific and will most probably change / being fine-tuned during application development.

Your XML is almost verbatim what you can put in a values resource file. In your project's res/values/ directory, create a configuration_resource_that_is_environment_specific.xml file (or whatever you wish to call it -- the name does not matter). In there, you can have string, integer, and boolean resources. You would retrieve those at runtime via a Resources object, which you can get via a call to getResources() from any Context, such as your Activity.

You can also then override those resource values via other resource sets (e.g., res/values-v11/ for versions of those values that should be different for API Level 11+).

That being said, I think most people just store this stuff in static data members in Java for simplicity.

C'mon, you must know what I mean ;-)

Not only is "configuration resource" unclear, but so is "environment specific", since we do not know what you consider your "environment" to be.

Upvotes: 1

Related Questions