Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store string values?In strings.xml or in constants class?

Tags:

android

In android, we can store string values either in strings.xml file or in some constants class as static final variable.Is there some reason for selecting one over another in some circumstances?

like image 739
pratim Avatar asked Dec 02 '22 15:12

pratim


1 Answers

In a nutshell:

value for use in code: use always constants class.Advantage: codes remain integrated and your package can be utilized in other projects/contexts. You can not do that with string.xml as it is not transported with your package.

value for display in UI: use string.xml. Advantage: you can use localization to display translated texts.

Some situation may arise when both option appears viable. You will have to then decide where are its related values are stored.

like image 115
pkt Avatar answered Dec 10 '22 12:12

pkt