Android res and assets resources, androidassets

Source: Internet
Author: User

Android res and assets resources, androidassets

Android applications can store resources in two directories: res and assets. Resources in the res directory can only be stored in the corresponding
Sub-directories (such as res/layout and res/values) cannot directly store Resources in the res directory. In the assets Directory
Resources can be stored at any time, or sub-directories at any level can be created. The main differences between res and assets are as follows.
1. Different resource reference methods
All resources in the res directory will generate corresponding int type variables in the corresponding subclass of the R class. These variables must be used.
To reference resources. For example, res/layout/main. xml is a layout file resource, and a file named main is generated in the R. layout class.
Variable, so you need to use R. layout. main to reference main. xml.
Resources in the assets Directory must be referenced directly by the file name. For example, assets/xyz. xml, assets/abc/test. db is
The assets Directory contains two resource files, where abc is the sub-directory of assets. You can use the following code to reference these two resource files,
And return the InputStream object corresponding to the resource file. The remaining operations are normal Java code input stream operations.

InputStream is1 = getResources (). getAssets (). open ("xyz. xml ");
InputStream is2 = getResources (). getAssets (). open ("abc/test. db ");


2. Different Processing Methods
In addition to raw, resource files in other resource directories are compiled in the resource subdirectories in the res directory.
After extracting the APK file, you cannot directly view the content of the resource file in XML format. Resources in the assets and res/raw Directories
The file will not be processed, so after the APK is decompressed, the resource files in these two directories will remain unchanged.

3. Different subdirectories
The res directory can only have one sub-directory, and these sub-directories must be pre-defined, such as res/layout and res/values.
Legal, and res/abc, res/xyz are not legal resource directories. You can create subdirectories at any level in the assets Directory (only restricted by the operating system)

Related Article

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.