Difference between getString() and getResources.getString()

15,607

Solution 1

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

 public final String getString(int resId) {
     return getResources().getString(resId);
 }

Solution 2

They are the same method, nothing special about them.

Solution 3

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

Share:
15,607
Valentin
Author by

Valentin

Updated on June 29, 2022

Comments

  • Valentin
    Valentin about 2 years

    I noticed that the Activity class has two different methods to get a String resource. This is possible by using:

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

    • getResources().getString(int id): Returns the string value associated with a particular resource ID. It will be stripped of any styled text information.

    I don't understand what's the difference between both methods. Can somebody tell me?

  • Serdar Samancıoğlu
    Serdar Samancıoğlu about 10 years
    not the same method, but two different methods those do the same job.
  • Tim
    Tim over 5 years
    this does not answer the question at all