5

Does anybody know anything about the internals of resource-id and R.java, or could at least reference me to read some more about it?

What is the meaning of the resource-ids? Are they some kind of addresses in the apk? Where are they saved in the compiled apk?

I tried looking some info about it, but most of the things I get are issues with importing it and what it does and in general.

Why I am asking these questions: I recently tried to dynamically load an apk that uses a resource here and looking at this I believe it is not even possible. I wanted to understand why.

Community
  • 1
  • 1
Ravit D
  • 907
  • 9
  • 27

2 Answers2

5

AFAIK

  • Android assigns ID for every resource.

  • The gen folder in a project contains the R.java references file which contains these generated values. These references are static integer values.

  • If you add a new resource file, the corresponding reference is automatically created in a R.java file.

  • Manual changes in the R.java file are not necessary and will be overwritten by the tooling.

    The Android system provides methods to access the corresponding resource files via these IDs.

For example, to access a String with the R.string.yourString ID in your source code, you would use following method defined on the Context class.

getString(R.string.yourString) 

I hope this helps a little

Durai Amuthan.H
  • 31,670
  • 10
  • 160
  • 241
0

check the documentation http://developer.android.com/guide/topics/resources/accessing-resources.html

Also Checkout Understand the R class in Android

Community
  • 1
  • 1
manya
  • 61
  • 2
  • 2
    link only answers are discouraged. elaborate your answer – Raghunandan Mar 02 '14 at 07:33
  • Thanks for your answer. I saw these links before but I still couldn't understand if the resource -ids are some kind of addressed and where they are saved in the compiled apk – Ravit D Mar 02 '14 at 07:39