0

Android's documentation on SharedPrefererences has this:

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
int defaultValue = getResources().getInteger(R.string.saved_high_score_default);

I searched online and most of the usage involving getResources().getInteger all use R.integer instead of R.string.

Is the documentation incorrect?

Boon
  • 40,656
  • 60
  • 209
  • 315

1 Answers1

2

getInteger() returns the value of an integer resource, which is denoted by an R.integer value in Java. R.string values are for string resources.

The SharedPreferences training guide that you point to has it wrong. I have filed an issue for that typo, which will get fixed sometime before the next ice age, if we're lucky.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks but why do most posts I see use R.integer instead of R.string within getInteger? This is one example: http://stackoverflow.com/questions/19297522/android-integer-from-xml-resource – Boon Oct 03 '15 at 18:04
  • 1
    Do you think there's a reason why they decided to use a string resource for an integer value in the docs then? – Andrew Brooke Oct 03 '15 at 18:04
  • 1
    @AndrewBrooke: Ah, now I understand the concern. That's a typo in the docs. – CommonsWare Oct 03 '15 at 18:06