Alternative to strings.xml for storing settings values in Android

June 6, 2011

This may be obvious to some but not me. ..

Like a good little programmer, I use strings.xml all the time in my Android applications which means that this file can get quite large. For a customer that wanted to be able to modify some settings before recompiling and distributing to their customers, I wanted to extract those variable “settings” into a different file for clarity.

It’s actually extremely easy to do. So easy that I thought it couldn’t possibly be that easy and started exploring more complicated routes.

All you have to do is create a new xml file e.g. “settings.xml” and then move your string value (e.g. <string name=”default_retry_time_value”>10</string>) from “strings.xml” into this new file.  That’s it!

You don’t need to update any views in your layouts to do to something like this android:text=”@settings/default_mcode_value”.

You just need to make sure that your settings.xml file is in res/values (same place as strings.xml) and Android will pick it up.

Advertisements

2 Responses to “Alternative to strings.xml for storing settings values in Android”


  1. Nice. How do you refer to these values in non-activity files? i.e. without a context?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: