I need to get the context to be able to get a resource. Like this:
getApplicationContext().getResources().openRawResource( R.raw.texture );
I’ve seen the getApplicationContext() in the android documentation but when I try to use it in the above code it doesn’t work – it doesn’t exist.
I can send the context through functions to get it to where it’s needed and it works. However, I find it cumbersome to send a variable through many functions that doesn’t need or use it. Then I would rather just try to get it in the function that do. But the getApplicationContext(), as in the android documentation, doesn’t work – http://developer.android.com/reference/android/content/Context.html
So how do I get the context so I can read resources? Or are my only option to send it through all my functions?
getApplicationContext()is a method of a Context. You have to have a context to get the resources. That’s just how it works.Just makes sure you’re not storing a reference to your context anywhere or you could cause a memory leak.