Reputation: 81
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
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:
productivity, The immediate result is that you can create many more things in less time.
clarity, people new to the project will have an easier time coming up to speed, since it's a "standard".
decrease the number of decisions you have to make.
eliminate the complexity of having to configure all and each of the areas of application development.
.. happy coding.
Upvotes: 1
Reputation: 176
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.
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