I have created a class which holds global vars:
public class GlobalVar extends Application{
private XData xData;
public XData getxData ()
{
return xData;
}
public void setXdata (XData Xdata)
{
this.xData = xData;
}
}
When I access this class using (GlobalVar)getApplicationContext() from the activities of my application its fine, but when I want to access it from another class (in this case its LocationListener), I cant use (GlobalVar)getApplicationContext()
How could I access the data?
You should implement the Singleton pattern on your GlobalVar class. And access them directly without getter/setter is recommended on android (read the performance guide).
You could also just make your xData variable static and than you can access it directly from everywhere.