Best way to get an Application Context into a static method in Android

Slapout picture Slapout · May 7, 2010 · Viewed 49.7k times · Source

I'm working on an Android application that has several Activities. In it I have a class with several static methods. I would like to be able to call these methods from the different Activities. I'm using the static methods to load data from an xml file via a XmlResourceParser. To create a XmlResourceParser requires a call on the Application Context. So my question is, what is the best way to get a reference to the Application Context into the static methods? Have each Activity get it and pass it in? Store it somehow in a global variable?

Answer

Karan picture Karan · May 7, 2010

The better way would be to pass the Activity object as parameter to the static functions.

AFAIK, there is no such method which will give you the application context in the static method.