5,595,645 Members 44,379 Now Online
XDA Developers Android and Mobile Development Forum

A sentence about usefulness of Resources

Tip us?
 
peter.sorotokin
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 7
Join Date: Nov 2013
Default A sentence about usefulness of Resources

Hi
In "Hello Android" book that i am reading , there is a sentence about usefulness of Resources that i can't understand .
Please give me some help about it .
The paragraph is :

"The resource compiler compresses and packs your resources and then
generates a class named R that contains identifiers you use to reference
those resources in your program. This is a little different from standard
Java resources, which are referenced by key strings. Doing it this way
allows Android to make sure all your references are valid and saves
space by not having to store all those resource keys
. Eclipse uses a
similar method to store and reference the resources in Eclipse plug-ins."

The underlined sentence has two part .

I understand part one in this way :
When there is some error in for example XML lay out files in Android project in Eclipse IDE ,
The IDE does not work correctly and some red signs are appeared next to files that have
error in left side project browser of Eclipse.

Is the thing that i understood is correct and complete ???

And about part two .
I cant understand it . What it says ??

Thanks for your help
 
EatHeat
Old
#2  
EatHeat's Avatar
Recognized Developer
Thanks Meter 1316
Posts: 901
Join Date: Jan 2013
Location: Calcutta
Quote:
Originally Posted by peter.sorotokin View Post
Hi
In "Hello Android" book that i am reading , there is a sentence about usefulness of Resources that i can't understand .
Please give me some help about it .
The paragraph is :

"The resource compiler compresses and packs your resources and then
generates a class named R that contains identifiers you use to reference
those resources in your program. This is a little different from standard
Java resources, which are referenced by key strings. Doing it this way
allows Android to make sure all your references are valid and saves
space by not having to store all those resource keys
. Eclipse uses a
similar method to store and reference the resources in Eclipse plug-ins."

The underlined sentence has two part .

I understand part one in this way :
When there is some error in for example XML lay out files in Android project in Eclipse IDE ,
The IDE does not work correctly and some red signs are appeared next to files that have
error in left side project browser of Eclipse.

Is the thing that i understood is correct and complete ???

And about part two .
I cant understand it . What it says ??

Thanks for your help
Whenever you add a resource(image, raw file, drawable, etc) in your app package, a separate class named as R.java forms in your gen folder. This cannot be edited by you and can only be modified by the IDE. All your resources will be given a unique id by which you can refer to them from your Java classes. It will revert to the generated version if you try to modify it manually.
[3.0+]Crius.
Customize your clock.


[2.2+]SnowBowl HD.
Enjoy the vacations!


 
nikwen
Old
#3  
nikwen's Avatar
Recognized Contributor
Thanks Meter 1231
Posts: 2,611
Join Date: Feb 2013
I guess that the way you understood the first part is correct. But it also applies to Java code. In the Android Java code you use these identifiers to load resources. You don't use hard-coded Strings. That way the compiler can check whether a resource with that name exists by checking whether the reference to the field in R is valid. If you had to put in hard-coded Strings, there would be no (easy) way to check that.

About the second part: I guess that it means that Strings need more storage space.

If we talk about usefulness of resources, this is a much bigger point to me: You can define different resources for portrait and landscape mode, for different countries, for different screen sizes, for different OS versions, etc. and Android cares about using the right one. You don't need to decide which one to use yourself.
You can also refer to them from Java and xml very easily. You just need to change one line of code to change a String that is used multiple times in your app. You can't forget one.

Link for a much more detailed description: http://developer.android.com/guide/t.../overview.html (including the sub-topics)
However, I guess that you won't need that many details in the beginning. Your book should explain the most important things.
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes