views:

60

answers:

2

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

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

+1  A: 

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.

benvd
+1  A: 

Pass in a Context (i.e. Activity) instance as a parameter object to static method. Then invoke getString on the parameter.

Konstantin Burov
This CAN be a bad idea. If you're storing references to contexts you could cause a memory leak
Falmarri
What made you think that I suggest to store a Context reference?
Konstantin Burov