Hydraxia
Hydraxia

Reputation: 81

How necessary is it to store values in the Resources folder?

From the Android Developer website: https://developer.android.com/guide/topics/resources/providing-resources

Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more.

You should always externalize app resources such as images and strings from your code, so that you can maintain them independently

As I understood we should store static content here that are used in coding so that they are easier to edit/store/manage, is that right? What other purpose do they have?

Couldn't I just have my own separate Java classes and define all my variables, finals etc there? Are these resources really essential?

I get it that for example, sound files, images etc. have to be stored somewhere, and in the Java classes we are referring to their location or tell the program how to reach them, but what about values like integers or Strings?

What do I lose by not assigning my values in .xml files in the Resources folder but directly in my Java classes? It seems like such a hassle to declare them, edit them in the .xml files, refer to them again in the Java files etc.

But! Of course I get it that it's done by a good reason, I just don't understand why yet.

Upvotes: 1

Views: 677

Answers (2)

med.Hamdan
med.Hamdan

Reputation: 300

Convention over configuration is a simple concept that is primarily used in programming. It means that the environment in which you work (systems, libraries, language…) assumes many logical situations by default, so if you adapt to them rather than creating your own rules each time, programming becomes an easier and more productive task...

some benifits:

  1. productivity, The immediate result is that you can create many more things in less time.

  2. clarity, people new to the project will have an easier time coming up to speed, since it's a "standard".

  3. decrease the number of decisions you have to make.

  4. eliminate the complexity of having to configure all and each of the areas of application development.

    .. happy coding.

Upvotes: 1

CMcAllister
CMcAllister

Reputation: 176

What other purpose do they have?

  • The allow you to have different configurations based on locale, device dimensions, and OS versions.

Couldn't I just have my own separate Java classes and define all my variables, finals etc there? Are these resources really essential?

  • For certain things yes you can and should have them defined in the Java.

I get it that for example, sound files, images etc. have to be stored somewhere, and in the Java classes we are referring to their location or tell the program how to reach them, but what about values like integers or Strings?

  • Strings that are displayed the the user should always be stored in a res folder. It makes localization much easier. However strings like intent keys can and in my opinion should be stored as a static private variable in Java.
  • Integers can be stored in Java. If the integer is a size for how much padding is given, or how big an image should be, then it should be in the res folder. However if it's integers to know what different values down from a database endpoint mean, then I would store that in Java.

What do I lose by not assigning my values in .xml files in the Resources folder but directly in my Java classes? It seems like such a hassle to declare them, edit them in the .xml files, refer to them again in the Java files etc.

  • The value you get is if you need it to change based on the locale/language set by the user, if the screen size matters (tablet, large phones, landscape, etc) or if you care about device version. For example different versions of Android do launch icons differently. I have a folder named minmap-anydpi-v26 and that has my icons in it. Then in my normal minmap folder, I have the "default" icon.

TL;DR For most cases the res folder helps with UI things (things the user sees). I would (mostly) only store Integers and Strings that have to do with UI items in the res folders.

Upvotes: 1

Related Questions