I've found the
R.string pretty awesome for keeping hardcoded strings out of my code, and I'd like to keep using it in a utility class that works with models in my application to generate output. For instance, in this case I am generating an email from a model outside of the activity.
Is it possible to use
getString outside a
Activity? I suppose I could pass in the current activity, but it seems unnecessary. Please correct me if I'm wrong!
Edit: Can we access the resources without using
You can use:
... everywhere in your application, even in static constants declarations. Unfortunately, it supports the system resources only.
For local resources use this solution. It is not trivial, but it works.
Unfortunately, the only way you can access any of the string resources is with a
Context (i.e. an
Service). What I've usually done in this case, is to simply require the caller to pass in the context.