Answer the question
In order to leave comments, you need to log in
Android: getResouces() vs context?
Such a question, even more like a theory: what is the difference between getting strings from the context itself and from resources?
That is, I can call getString from the context itself, but often I see people calling it with context.getResources().getString() and I can't find an answer why they do it. Is there any sense?
Answer the question
In order to leave comments, you need to log in
Nothing different. See Context's sources:
@NonNull
public final String getString(@StringRes int resId) {
return getResources().getString(resId);
}
getResources() is more reliable, not all resources are called directly from the context, some do not write an error and then you have to catch it for a long time
, I won’t tell you exactly which ones, but when I just started writing under android, I had a few very fun hours because of this, since then everything except for getString(), and I often call it via getResources()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question