I am using the android.app.Application class (a subclass) to store some "global" information. An example is the user location the last time we grabbed it from the GPS/wifi. My question is whether I should be storing these "globals" as static variables or instance variables. Not sure which scenario is better or more correct.
Scenario A: using static variables --
public class MyApplication extends android.app.Application {
private static Location myLocation;
public static Location getLocation() {
return myLocation;
}
public static void setLocation(Location loc) {
myLocation = loc;
}
}
Scenario A: usage --
loc = MyApplication.getLocation();
MyApplication.setLocation(loc);
Scenario B: using instance variables --
public class MyApplication extends Application {
private Location myLocation;
public Location getLocation() {
return this.myLocation;
}
public void setLocation(Location loc) {
this.myLocation = loc;
}
}
Scenario B: usage --
loc = getApplication().getLocation();
getApplication().setLocation(loc);
Thank you.