Tidbit Tuesday: What to do with your ridiculously long strings.xml

Bite-size Android nuggets of knowledge

Andrew Orobator
2 min readDec 13, 2016

--

If you’ve been doing Android development for a reasonable amount of time you’ll know about String resources. These are used instead of hard-coded strings in code so that when you’re translating your app, you can simply use string resources and Android will figure out what language to use when. You can read more about that here. After you’ve been a good developer and you’ve used the string resources for every string in your app, you might notice something…Your strings.xml file is absurdly long. Sometimes hundreds (hopefully not thousands 😬) of lines long. You struggle when looking for string resources and you begin to fill with feelings of dread every time you open strings.xml. Fear not! For I have a solution:

Split up your strings.xml by feature!

Instead of putting all of your app strings into one file, you can break them into several files. I usually have a feature_strings.xml for every feature of my app. The best part is, all the references stay the same. Whether in xml as “@string/your_string_here” or code as R.string.your_string_here, these references will be the same regardless of the file they’re in, so long as they’re properly declared as string resources. Hopefully this tidbit tidies up your codebase! If you have any tidbits you’d like to share about tidying up your codebase, feel free to leave it in the comments below, and happy coding :)

--

--