0

What is the algorithm to generate R. Will the param in R be always the same?

SharedPreferences preference = getPreference();
Object object = preference.getString(R.id.xxx); 

I want to know that the value of R.id.xxx will change or not.

-----------------------try to ask the question more clearly-----------------

v1 = R.id.listview;

then clean the project;

v2 = R.id.listview;

will v1 = v2 all the time?

I tested like this. Print the R.id.xxx,clean project and print the R.id.xxx again. The result is the same.

But I don't know in different IDE, that value of R.id.xxx will change(the AAPT version is all the same or not).

user2545386
  • 447
  • 3
  • 16

2 Answers2

1

Android R.java is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory.

Note: If you delete R.jar file, android creates it automatically.

Edit:

for more details about R.java , kindly refer here

Sathish Kumar J
  • 4,280
  • 1
  • 20
  • 48
1

I found the answer.But unluckily, it's not in english. Now I'll try to answer the question myself.If there's errors,please tell me.


There is a file in res/values/public.xml in the sdk directory.

The value will always read public.xml first.

So now you know if you didn't delete the file, the value will always the same.

But you delete it,I don't know what will happen.I'm afraid my application will have some error, so I didn't do the experiment.


If anyone has a link of article about how android generate R in English,comment or create a new answer thanks.

user2545386
  • 447
  • 3
  • 16
  • What if you create a new field in a layout with an id, or removing one ? – AxelH May 12 '16 at 08:09
  • I tried add an id,the value is the same.And I read an article,it said to avoid Compatibility problems,the values will read from public.xml first. – user2545386 May 12 '16 at 08:14
  • Good to know, for Preference fragment, I had to create some ugly controler to get every preferences id, default value, ... it recover every data from R on generation, this was not perfect, I guess I could have use the generated value, with probably I small risk. – AxelH May 12 '16 at 08:18
  • If you can read Chinese this article has more information.http://blog.csdn.net/luoshengyang/article/details/8744683 – user2545386 May 12 '16 at 08:21
  • Nope, that's not going to help me :P but thanks for the link. – AxelH May 12 '16 at 08:34