Need to access resources from non-context class without passing context through deep call stack.
I’ve already read all answers on this topic, but this class is not created from Activity, and it’s really far from it. The way to send context through all calls is not a variant, because it’ll require to send it through a number of classes and methods which does not any need to know something about context.
Do I have any chance to access resources without passing context through a really deep call stack? Any static methods needed? It would be really amazing if it’s impossible to get application resources from any place of application with an easy and natural way.
You can extends Android’s Application class and implement it as a singleton which will make it globally available.
If you do this it requires some work in the AndroidManifest.xml. This will tell the framework to load your Application instead of the default application.
This will easily give you a mechanism to grab your Application context whenever necessary. You can even implement a static method that returns your resources, but the following should work.
Don’t know if you have tried this, but it should work. I didn’t test this code, so it may take some tweaking, but you should get the idea.