K
K
Konstantin Dovnar2015-10-16 21:48:48
Android
Konstantin Dovnar, 2015-10-16 21:48:48

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

2 answer(s)
F
FoxInSox, 2015-10-16
@SolidlSnake

Nothing different. See Context's sources:

@NonNull
public final String getString(@StringRes int resId) {
    return getResources().getString(resId);
}

O
Oleg Gamega, 2015-10-16
@gadfi

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 question

Ask a Question

731 491 924 answers to any question