Use of assets and AW files for Android interview

Source: Internet
Author: User

In the establishment of the project will generally default to establish the assets file, of course, we can also create a raw folder under the Res file, where the surface can hold some multimedia files or text information, can be used in our program.

Assets the following files will not be compiled, and the path can be used to access the contents. The files in raw are automatically compiled and we can find the corresponding IDs in the R.java file.

One of the more important is to get the resource methods in assets and raw (for file test.txt)

Assets:inputstream InputStream = = Getassets (). open (Test.txt);

Raw:inputstream InputStream = Getresources (). Openrawresource (R.raw.test);

Add:

We all know that the establishment of an Android project will produce assets and res two folders, in theory they are the folder to store resources, then what is the difference between them?

1.assets: The corresponding tag will not be generated under the R.java file, and the resources stored here will be bundled into the program installation package when the package is run.

2.res: tokens are generated under the R.java file, where the resources are used to determine which ones are in use when the package operation is run, and the file resources that are not used are not packaged in the installation package.

You can actually define the directory under the Res folder:

Res/anim: This is an animated resource.

res/xml: You can use GetResource () in activity. GetXML () Read the resource file here

Res/raw: files in this directory can be copied directly to the device, compile the software, the data here does not need to compile, directly into the program installation package, using the method is GetResource (). Openrawresources (ID), where the parameter ID is in the form of r.raw.xxx.

Add a point:res can only establish a system-approved directory, and can only establish a level, the following can not have subdirectories, and assets below may be placed any number of any multilevel. "From 2 floor reviews"

Use of assets and AW files for Android interview

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.