I’m developing an application for Android, and at one point the user chooses a region, after which the contents of all parts of the app is changed. Therefore I need to access an integer throughout the program. I have considered a singleton class, but I can’t figure out how to add just an int, a get() and a set() to it (I want to be able to read everywhere and write in two classes(everywhere is fine)).
Should I simply declare it global?
This is what I’ve got going now, is it ok?
public enum Region {
INSTANCE;
private int rID =0;
public void setRID(int rID) {
this.rID=rID;
}
public int getRID()
{
return rID;
}
}
To be accessed with
Region.INSTANCE.setRID(5);
I went with an enum:
Which I access with