Valentin
Valentin

Reputation: 5598

Difference between getString() and getResources.getString()

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

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

Upvotes: 77

Views: 18379

Answers (3)

Sergey Shustikov
Sergey Shustikov

Reputation: 15821

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

Upvotes: 2

dacwe
dacwe

Reputation: 43504

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

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

Upvotes: 95

jtt
jtt

Reputation: 13541

They are the same method, nothing special about them.

Upvotes: 4

Related Questions