I am trying to get value from SharedPreferences and storing it inside of an static variable. The problem is sometimes I am getting null value from static variable but SharedPreferences has value.
I have stored value via this process:
SharedPreferences sp = u.returnShare();
SharedPreferences.Editor editor = sp.edit();
StaticVariables.userId = sp.getString("UserId", "default");
Don’t use static variables, its bad practice. Android can destroy you application’s process at any time and later recreate it by recreating activities as necessary. If you’re creating your static variable in the “first” activity then it wont get initialized when the 2nd or 3rd are started first.