What is the use of the res/values/public.xml file on Android?
2014-03-26 10:15
2191 查看
http://stackoverflow.com/questions/9348614/what-is-the-use-of-the-res-values-public-xml-file-on-android
add
comment
activeoldestvotes
I've searched on Google, but couldn't find any relevant results. I also checked the official Android docs and this page (for all the available resources) was all I could find. The relevant links (to the res/values/directory) I found on this page were: string resources style resources more resources These pages don't tell anything about the res/values/public.xmlfile. Here is an example I found for this type of file.
|
share|improve this question | asked Feb 19 '12 at 11:05 Igor Popov 2,93511737 |
comment
2 Answers
activeoldestvotesup vote37down voteaccepted | The file res/values/public.xml is used to assign fixed resource IDs to Android resources. Consider these set of string resources in res/values/strings.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="string1">String 1</string> <string name="string3">String 3</string> </resources> The Android Asset Packaging Tool (aapt) might assign the following resource IDs for these resources when the app is compiled: public final class R { // ... public static final class string { public static final int string1=0x7f040000; public static final int string3=0x7f040001; } } Now, change the set of string resources to <?xml version="1.0" encoding="utf-8"?> <resources> <string name="string1">String 1</string> <string name="string2">String 2</string> <string name="string3">String 3</string> </resources> and you'll notice that the resource ID for @string/string3has changed: public final class R { // ... public static final class string { public static final int string1=0x7f040000; public static final int string2=0x7f040001; public static final int string3=0x7f040002; // New ID! Was 0x7f040001 } } To prevent this, you can use res/values/public.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <public type="string" name="string3" id="0x7f040001" /> </resources> which will result in the resource IDs being assigned as follows: public final class R { // ... public static final class string { public static final int string1=0x7f040000; public static final int string2=0x7f040002; public static final int string3=0x7f040001; // Resource ID from public.xml } } Applications rarely have any use for res/values/public.xml since the resource IDs assigned to resources does not matter. When they change, the entire application is rebuilt anyway so any references in Java code to resources by resource ID will be updated. The most significant user of res/values/public.xml is the Android platform itself. Applications built against old versions of Android assumes that certain resource have a certain resource ID. For example, the Android resource @android:style/Thememust always have the resource ID 0x01030005 for the platform to be backwards compatible with apps built against old versions of the platform. If you are curious about more details on how resource IDs are assigned, please refer to this answer: How does the mapping between android resources and resources ID work?
| ||||
comment |
up vote2down vote | Is it not a file just for the use authors of the OS code to define a mapping between symbolic names and system resource ids? You'll find it in your SDK at YOUR_SDK_LOCATION\platforms\android-??\data\res\values. It's headed This file defines the base public resources exported by the platform, which must always exist and has the caveat: IMPORTANT NOTE FOR ANYONE MODIFYING THIS FILE READ THIS BEFORE YOU MAKE ANY CHANGES This file defines the binary compatibility for resources. As such, you must be very careful when making changes here, or you will completely break backwards compatibility with old applications It has entries such as <public type="attr" name="smallScreens" id="0x01010284" /> <public type="attr" name="normalScreens" id="0x01010285" /> <public type="attr" name="largeScreens" id="0x01010286" /> in it - all system resurce ids, so anyone changing entries will break their code, insomuch as it won't run on a standard device.
| ||||||||||||
|
相关文章推荐
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental……
- 你好,色彩 android:background="@color/white" [create file color.xml at res/values/]
- 导入android工程后出现The resource is not on the build path of a java project
- 你好,色彩 android:background="@color/white" [create file color.xml at res/values/]
- 色彩大全,android:background="@color/white" [create file color.xml at res/values/]
- Part 68 - What is the use of NonAction attribute in mvc
- what is the use of truncate command
- android:background="@color/white" [create file color.xml at res/values/]
- 安装vmware-tools出现"what is the location of the "ifconfig"program on your machine?"
- 【Android】Android import和export使用说明 及 export报错:jarlist.cache: Resource is out of sync with the file syst解决
- What if a data file of the Non-System tablespace is missing?
- Layout inflation is the term used within the context of Android to indicate when an XML layout resou
- android:background="@color/white" [create file color.xml at res/values/]
- what is the purpose of the rptproj.user file
- 你好,色彩 android:background="@color/white" [create file color.xml at res/values/]
- linux安装问题:what is the location of the gcc program on your machine
- linux安装问题:what is the location of the gcc program on your machine
- android.util.AndroidRuntimeException Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? com.uethinking.microvideo.manag
- 自定义色彩xml文件《android:background="@color/white" [create file color.xml at res/values/]》
- 解决办法:Synchronous XMLHttpRequest on the main thread is deprecated because of its