Reputation: 63
So I've noticed that there seem to be two ways to get the same data, and I'm not sure if there are guidelines to when you should use either (other than, bypassing the getResources could be memory saving if you don't actually want to use the object more than once). But other than that I would like to know if there are guidelines or reasons to use
Context.getText(id) vs Context.getResources.getText(id)
Can anyone help?
Upvotes: 6
Views: 1495
Reputation:
you can see source code of above at grepcode.com
There is literally no difference
Upvotes: 0
Reputation: 8285
If you just want the text, you can use the Context.getText(id)
method. Getting the resource with Context.getResoures()
allows you to test other properties of it.
Upvotes: 1
Reputation: 13801
There is no difference. The source for getText(id) is:
/**
* Return a localized, styled CharSequence from the application's package's
* default string table.
*
* @param resId Resource id for the CharSequence text
*/
public final CharSequence getText(int resId) {
return getResources().getText(resId);
}
You can see for yourself at Context.java on netmite which has a version of the Android source.
Upvotes: 6