mardi 24 février 2015

Different ways to retrieve a string form R.java file (Android)

Let's imagine we had this text inside values/strings.xml



<string name="some_text">HELLO WORLD</string>


I can call this string from anywhere inside my project like so:



String s = String.valueOf(R.string.some_text);


Today I learnt this other way to do exactly the same job:



String s = getResources().getString(R.string.some_text);


Does anyone know if there is any advantage in using the second way? The first one seems shorter and easier to remember.


Thanks


Aucun commentaire:

Enregistrer un commentaire