Android: getString(R.string) in static method

Saren Inden picture Saren Inden · Sep 29, 2010 · Viewed 31.9k times · Source

When programming for Android sometimes you have to use static methods. But when you try to access you resources in a static method with getString(R.string.text) you'll get an error. Making it static doesn't work.

Does anyone knows a good way around this? The resource files in Android are very helpful for creating things in different languages or making changes to a text.

Answer

benvd picture benvd · Sep 29, 2010

One way or another, you'll need a Context for that... For static methods this probably means you need to pass along a Context when calling them.