Android Resource Management

Source: Internet
Author: User

Through the process of compiling and packaging Android application resources, the resulting application resources are packaged in an APK file along with the application code. The Android application runs through a resource manager called Assetmanager to read the resource files packaged in the APK file.
access resources within the app:Each activity component of an application is associated with a Contextimpl object, which is a Contextimpl object that describes the running context of the activity component. The activity component inherits from the context class, and Contextimpl is inherited from the context class. Most of the member functions that are called by the activity component are forwarded to the corresponding member function of the Contextimpl object it is associated with, including the two member functions Getresources and getassets that are used to access the application resources.The member function of the Contextimpl class Getresources returns a Resources object, with this resources object, you can access the compiled application resources through the resource ID.The member function of the Contextimpl class Getassets returns a Assetmanager object,With this Assetmanager object, you can access application resource files that have been compiled or not compiled by using the file name.
Implementation of the         resources class: in fact, The resources class also accesses the compiled application resource file through the Assetmanager class, but before accessing it, it finds the corresponding resource file name based on the resource ID. In an Android system, a process can load multiple applications at the same time, that is, multiple apk files can be loaded simultaneously. Each apk file should have a global resourses object and a global Assetmanager object in the process. The global resourses object is stored in the member variable mresources of a corresponding Contextimpl object, and this global Assetmanager object is stored in the member variable resourses of this global Massets object. The resources class has a member function getassets, through which it can obtain assetmanager stored in the member variable massets of the resources class, for example, The member function of the Contextimpl class is getassets to obtain a non-compiled resource file that can be used to access the application by calling the member function of the resources object that the member variable mresources points to Getassets 。

To Access system resources: Android applications need access to the system's resources in addition to accessing their own resources. The resources of the system are packaged in the/system/framework/framework-res.apk file, which is managed in the application process through a separate resources object and a separate Assetmanager object. This individual resources object is stored in the static member variable msystem of the resources class, and we can obtain the resources object by getsystem the static member function of the resources class. This single Assetmanager object is stored in the static member variable ssystem of the Assetmanager class, which can also be obtained by getsystem the static member function of the Assetmanager class.

This article from "Tech record" blog, declined reprint!

Android Resource Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.