0

I just have few questions to solidify my understanding to R.java class.

(1): Does it generated at run-time or compile-time? To test it, I created a new 'Button' with a text, the 'id' of the 'Button' is 'actMain_btnTest' and the name attribute of its text in 'strings.xml' is 'btn_test'. Then in the java file I referred to the 'Button' using 'findViewById' and it was accessible. Therefore, I would say that the 'R.java' can be generated at compile time. But, then I navigated to 'R.java' to make sure that the 'actMain_btnTest' and 'btn_test' was added to 'R.java', but surprisingly, they were not existing!! Now, anew question popped-up, how the 'id' was accessile while it was not yet added to 'R.java'?!

(2): What is the relation between 'R class' and 'Android Resource Manager'? how they work together?is it only for localization?!

(3): Since 'R class' contains sub-classes which contain 'ids' of the App's resources, and each 'id' is assigned to a value. For example,

public static final int request_identifiers=0x7f060019;

What does '0x7f060019' refer to? is it an address in the memory??!!

Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • Helpful SO explanations and links at: https://stackoverflow.com/questions/6804053/understand-the-r-class-in-android – Lew Perren Jul 09 '17 at 06:56

1 Answers1

0

It is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory.

If you create any component in the activity_main.xml file, id for the corresponding component is automatically created in this file. This id can be used in the activity source file to perform any action on the component.

RonTLV
  • 2,376
  • 2
  • 24
  • 38