androidandroid-resourcesgetstring

Difference between R.string.xxx and getString(R.string.xxx)?


What is the difference between two ways to obtain a string from resources:

setPositiveButton(R.string.some_string);

OR

setPositiveButton((getString(R.string.some_string));

?

In both cases I get the same result.


Solution

  • R.string.some_string
    

    is a public final static int that is a fixed ID to a specific String in your R.java file. This is generated automatically.

    getString(R.string.some_string)
    

    returns the String referenced by the above by reading the R.java file.

    It depends on the implementation of

    setPositiveButton(String)
    

    and

    setPositiveButton(int)
    

    what difference internally is made, like with error checks.