What’s role of R.java file that generated by Android SDK?

Question

What’s the role of the R.java file that is automatically generated by the Android SDK?
Please explain in detail with an example.

Explanation

the role of the R.java file that is automatically generated by the Android SDK is as follow:

R.java file is a file that is auto-generated by Android Asset Packaging Tool. In this file, there is resource ID’s which is required for the application.

The files which are located in the resources in the res folder can be generally seen in. XML files. And this type of file is not understood by the compiler in java. So, AAPT converts these XML files into resources. Which is next understood and used by the java compiler. And These are the resources that are accessed through java files using the R.java file. So thus after knowing this we can see there is a connection between file .xml and java compiler. We can also say that Android SDK creates an R.java file to store the pointers to all the resources.

R.java file is mainly used to access the resources quickly in the project. So that if there is any update like delete or add in the project, the R.java file will get automatically updated. R class contains subclass which contains resource address, that is used in the program.

Resource ID has the following parts:

    • Resource Type:
      It is a type where it is the subclass or category in which there is the required id is exits.
    • The resource name:
      This is the filename or the attribute.

For Example, R.drawable.icon
It is a resource to the icon. And here subclass is drawn able in the main class r. And the attribute name is an icon. Now R file can sometimes be deleted or updated or modified, but each program has its R file. So that the file is deleted new file will be auto-created. And this will happen when the application will be in use.

 

Also read, Draw a use case diagram that shows two examples

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *