Why Default Resources Are Important

Whenever the application runs in a locale for which you have not provided locale-specific text, Android will load the default strings from res/values/strings.xml. If this default file is absent, or if it is missing a string that your application needs, then your application will not run and will show an error. The example below illustrates what can happen when the default text file is incomplete.

Examp/e:

An application's Java code refers to just two strings, text_a and text_b. This application includes a localized resource file (res/values-en/strings.xml) that defines text a and text b in English. This application also includes a default resource file (res/values/strings.xml) that includes a definition for text a, but not for text b:

• This application might compile without a problem. An IDE such as Eclipse will not highlight any errors if a resource is missing.

• When this application is launched on a device with locale set to English, the application might run without a problem, because res/values-en/strings.xml contains both of the needed text strings.

• However, the user will see an error message and a Force Close button when this application is launched on a device set to a language other than English. The application will not load.

To prevent this situation, make sure that a res/values/strings.xml file exists and that it defines every needed string. The situation applies to all types of resources, not just strings: You need to create a set of default resource files containing all the resources that your application calls upon — layouts, drawables, animations, etc. For information about testing, see Testing for Default Resources.

0 0

Post a comment