Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Bijay Sharma
Bijay Sharma
2,745 Points

R.string.xxxx returns an integer. Why ? Help me understand this.

How R.string.xxx returns int, and that integer is used to refer to the String Resources

1 Answer

All of Android's resources are accessed via an integer which is used as a unique identifier for each of the resources, strings, images, audio files etc etc. Android essenitally creates a lookup table and uses an integer as a key to identify each of these resources so you dont have these pieces of static content dotted around your app and gives you a nice easy place to store everything and you know exactly where to look when something needs changing.

I don't know for sure but i would imagine that the reason they use an int is because it only uses 32 bits of data to store an integer in and this is the most efficent way to reference some static content without passing around Bitmap's etc every where.