The Android resource management framework is actually implemented by the Assetmanager and resources two classes. Where the resources class can find the resource based on the ID, and the Assetmanager class finds the resource based on the file name. In fact, if a resource ID corresponds to a file, the resources class will first find the resource file name based on the ID, and then give the file name to the Assetmanager class to open the corresponding file, as shown in procedure 1.
The resources class is actually going through the Assetmanager class to find the resource name based on the resource ID, because the resource ID corresponds to the resource name in the RESOURCES.ARSC file that is packaged in the APK. When the resources class looks for a resource that corresponds to a file, it will then hand over the resource name to Assetmanager so that the latter can open the corresponding file, otherwise the resource name found in the previous step is the final search result.
The RESOURCES.ARSC file inside the APK package is generated when the application resources are compiled, and then packaged in an APK package along with other compiled and native resources.
In the process of resource lookup, they can be attributed to two main categories . The first category of resources is not due to documents , and the second category of resources is to the due documents , for example,
1. String resources are compiled directly in the RESOURCES.ARSC file,
2. The interface layout resource is the corresponding individual file within the APK package.
As mentioned above, a resource that does not correspond to a file only needs to perform a conversion from the resource ID to the resource name , and the resource that should have the file must have a root resource name to open the corresponding file .
We know that when each activity component is created, its member function OnCreate will be called, and in the activity component's member function OnCreate, Basically, we call Setcontentview to set the interface of the activity component without exception. When calling the activity component's member function Setcontentview, you need to specify a resource ID for the layout type. So that the Android Resource Management framework can find the interface that specifies the XML resource file to populate (inflate) as the activity component. Next, let's start with the member function Setcontentview of the activity class, which analyzes the process of finding the layout resource in the Android Resource management framework, as shown in 2.
Search process Analysis for Android app Resources