Advantage of declaring a string as a resource in strings.xml

I read in many places that you should declare String objects in a resource file, but I have not read about any advantages anywhere.

I already declared all my lines that I have in my layouts as resources, but I did not do this in my classes.

My question is:

What are the benefits of declaring strings as a resource? Are there any memory benefits?

+4
source share
3 answers
  • Internationalization,
  • Saving all your lines in one place (where they can be changed globally),
  • Changing device-based strings (mdpi / large / portrait) ... I mean, it would be very rare for the latter, but it is possible.
  • Sharing the same line among many layouts (this will happen in any application that is not tiny)
+7
source

The top one that I believe is: Translations! Place the new strings.xml file in the desired folder, and the application is translated for each device.

But there is a question of organization. As with the layout, you usually don't build code because this is not the place for it. The code is intended for processing material. A string is another resource that your code will use to display material on the screen.

+2
source

One of the main advantages is localization: you remain independent of the code and just have to provide a different XML file for each language that you want to support.

+1
source

Source: https://habr.com/ru/post/1445082/


All Articles