I have a basic understanding of java and android but am still new and am struggling to find the correct way to save a variable and be able to access it/read it from other classes/activities. I have seen singletons but I am confused if it is the right way and how it would look, also do I need to make sure its thread safe?
Is there a better way that I am unaware of?
Basically I have a login that gets a username and some info about that user. How can I save that to a class/singleton and access it later?
EDIT
after some more searching I found this example:
public class Drivers {
private static Array drivers;
public static void setDrivers(Array c){
drivers = c;
}
public static Array getDrivers(){
return drivers;
}
}
and get and set like this:
public class AnyClass {
{
int clicks = ActionClass.getDrivers();
ActionClass.setDrivers(0);
}
Would this work/be correct?