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()
![Valentin](https://i.stack.imgur.com/4W2g9.jpg?s=256&g=1)
Author by
Valentin
Updated on June 29, 2022Comments
-
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 about 10 yearsnot the same method, but two different methods those do the same job.
-
Tim over 5 yearsthis does not answer the question at all