Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different ways of getting a string resource

What is the difference between getResources().getString(...) and getString() when called from my activity? I read that getText(...) returns stylized text, but when should I use getResources() as opposed to directly calling getString()?

like image 624
Phillip Avatar asked Jul 28 '12 01:07

Phillip


2 Answers

They are the same nothing special about them if you fetch the Android source code and specially the Context Class for exemple

 public final String getString(int resId) {
     return getResources().getString(resId);
 }
like image 161
K_Anas Avatar answered Sep 30 '22 16:09

K_Anas


getString() is a convenient way since it is used regularly (you don't need to type getResources()…). Other than that, they're same.

like image 41
Anh3Saigon Avatar answered Sep 30 '22 17:09

Anh3Saigon