Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Which is the best way to store URLs? Static data members or in String.xml?

I have a large number of urls (almost more than 30) in my application. I have placed them in a class as static data members. I want to ask is it better than storing in String.xml file?

like image 326
Khawar Raza Avatar asked Dec 12 '11 13:12

Khawar Raza


People also ask

Why do we use string xml in Android?

String. xml file contains all the strings which will be used frequently in Android project. String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.

Why should you use string resources instead of hard coded strings in your apps?

It allows you to easily locate text in your app and later have it translated. Strings can be internationalized easily, allowing your application to support multiple languages with a single application package file (APK).

Why do we store strings as resources in xml?

The purpose of strings. xml (and other *. xml resource files) is to regroup similar values in one place. This facilitates finding values that would be otherwise buried in the code.

In which folder can you find the string resource file strings xml?

The XML resource files containing localized strings are placed in subfolders of the project's res folder. Android uses a special folder-naming scheme to automatically choose the correct localized resources—for example, the folder values-fr would contain a strings.


2 Answers

Store them as string resource if the URL will not be changed. It is similar to public static final

like image 82
Sunil Kumar Sahoo Avatar answered Sep 21 '22 13:09

Sunil Kumar Sahoo


Storing them as string resources only gives an advantage if you have different URLs for different languages/locales. Otherwise there's no benefit.

like image 21
Graham Borland Avatar answered Sep 20 '22 13:09

Graham Borland