Difference between getString () and getResources.getString ()

I noticed that the Activity class has two different methods for getting a String resource. This is possible using:

  • getString(int resId) : Return the localized string from the default string table of the application package.

  • getResources().getString(int id) : returns the string value associated with the specific resource identifier. It will be stripped of any textual information in style.

I don’t understand what is the difference between both methods. Can someone tell me?

+43
android string resources
Jan 25 '12 at 8:16
source share
3 answers

They are the same as Activity.getString(int) do exactly that:

  public final String getString(int resId) { return getResources().getString(resId); } 
+62
Jan 25 '12 at 8:25
source share

They are one and the same method, nothing special about them.

+4
Jan 25 '12 at 8:23
source share

In fragments, you can also use getString() instead of getActivity().getString()

+3
Jun 14 '15 at 13:54 on
source share



All Articles