Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

you can see source code of above at grepcode.com

There is literally no difference

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top