The class contain this parameter like thie
public class Global {
public static String USER_ID = "";
public static String USER_NAME = "";
public static String USER_PASSWORD = "";
}
the USER_ID,I set once when do login.(for example Global.USER_ID = “12345”).
And a thread running on the background do that every 5 minute post some data(contains this USER_ID) to webservice.
the question is
when the thread running long long time (about one day).
I found the parameter USER_ID return back to “”, is not the “12345”.
Why???
anyone know it?
I think your class is removed from the memory by class loader (during GC) and it is loaded next time you use Global class.
My Suggestion will be to use Singelton class for this you can have something like this
Now wherever you want to use this class you can get this object, the singelton logic ensures that their is only one object which is shared among all.
You can get the reference in your threads using
Now you can use variables i.e. USER_ID using global.USER_ID
Since you have a reference of global object GC will not remove that from memory till your thread is alive.
NOTE
I have used public variables just for the illustration however they are not recommended in most cases.
EDIT
For saving user data I recommend SharedPreferences and you can use them as follows:-