문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top