I get why Android requires you to pass a Context object when trying to get a view for example, show a Toast, etc.
However, I don't really get the point for requiring it to access resources that could be shared by different Contexts in your application.
I several times found myself trying to access a resource from a utility class using a static method or something along those lines, and find it pretty annoying to require a passing of a Context param.
I fail to see where something could go south with this.
From the official documentation :
Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.
In clear, the context is the middleman between the telephone resource, and your code. And it seems logical, that you cannot access to this from everywhere.
The reason you can only access to Context in Activity and Application classes, is because both derives from Context :
java.lang.Object
↳ android.content.Context ↳ android.content.ContextWrapper ↳ android.view.ContextThemeWrapper ↳ android.app.Activity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With