This website uses cookies on its adverts and sponsored links. By clicking the "Accept" button you are consenting to their use.

Read more

Accept


Mobile Tech Tracker
≡ sections
Coding Courses

Tech Advice

Career Advice

Cybersecurity

Opinions

About

Welcome to Mobile Tech Tracker. Our mission is to help technically-minded people to become better versions of themselves and to help ordinary people to use modern smart technologies to their own advantage.

We can provide consulting or programming training services, including authoring of courses and books. For enquiries, please contact consulting@mobiletechtracker.co.uk.


3 reasons to use strings.xml in Android application

One of the best practices of Android application development is to write all strings in a single configuration file, which is strings.xml. This puzzles many developers at first. Although nothing stops you from writing text in your layout controls directly and this would not stop the application from running, the mostly widely used Android IDEs, such as Eclipse, will show you warnings if you do.

The suggested practice is to write a key-value pair in the strings.xml file where the key is what you refer to in your layout control such as TextView or Button as "@strings/key" and the value is the actual text that you want the view to display.

To many people, this practice would seem inefficient, as it obviously takes more time to write the configuration entry than to just write text in one place, especially when the key has to be longer than the actual value that it represents. After all, this methodology is not generally used in development of different types of software. However, there are some very valid reasons why properly using strings.xml in Android application is a good idea. Here are the 3 most fundamental ones.


1 Labels shared by many layouts or controls

Shared strings can be considered to be the same as static variables used by several classes in any software application. So, if your app uses the same title on several layouts it would be very easy to update it everywhere. As long as the key of the string value remains the same, all you have to do is to change the value in strings.xml file.


2 Localisation

Using strings.xml file allows you to translate your app into different languages without rewriting every single layout or re-publishing the whole application. All you have to do is to create localised version of "values" folder (e.g. values-fr for French, values-jp for Japanese) and place its own version of string.xml file there. Users will see the text in the same app in different languages depending on the device settings.


3 Risks with tablet-based development

Many developers chose to write their app on Android devices directly by using specialised IDEs such as AIDE. There are many pros and cons of this approach; however one of the annoying things is that it is fairly easy to accidentally delete something without any options to restore it.

Although strings.xml file will not eliminate the risk of accidentally deleting the files, it will mitigate it somewhat. If deletion has occurred, you would still need to write the code from scratch. However, you will not have to write all the text values within it. Same applies to using shared colour codes and dimensions.


If you feel that there are more important reasons for using strings.xml, please write to us on info@mobiletechtracker.co.uk and we will be happy to add them.



Written by

Posted on 29 Aug 2015



Tech Advice Articles


Applying clustering on OpenLayers map

Applying clustering on OpenLayers map


Why you absolutely need SignalR for ASP.NET development

Why you absolutely need SignalR for ASP.NET development


Pros and cons of Blazor for web development

Pros and cons of Blazor for web development


Web GIS: Making modal pop-up on an OpenLayers map

Web GIS: Making modal pop-up on an OpenLayers map


Using .NET Core SDK projects in .NET Framework

Using .NET Core SDK projects in .NET Framework


Learning .NET Core from scratch

Learning .NET Core from scratch


Playing audio on .NET Core with NetCoreAudio

Playing audio on .NET Core with NetCoreAudio


Building .NET Core sound application - part 3

Building .NET Core sound application - part 3


Building .NET Core sound application - part 2

Building .NET Core sound application - part 2


Building .NET Core audio application - part 1

Building .NET Core audio application - part 1


Share this:

Facebook Google LinkedIn Twitter Become a Patron!


More from Tech Advice











Privacy Policy

© Mobile Tech Tracker. All rights reserved. Unauthorised copying of any of this website's content is prohibited under international law.

For any queries, comments or suggestions, please write to info@mobiletechtracker.co.uk.