In my application, after logging in, I save user data, such as (username, identifier, email, etc.) in a sharedPreference file so that I can access them anywhere in the application, I do it like this:
public void put(String fileName, String key, String value)
{
SharedPreferences sharedPref = getContext().getSharedPreferences(fileName, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(key, value);
editor.commit();
}
now I spawned another thread that will work independently (something like Sync), I refer to sharedPreference, like this,
mContext.getSharedPreferences(fileName, Context.MODE_PRIVATE);
but all values in this particular preference are returned as null, I'm doing something wrong,
PS: - If I kill the application and the same thread appears again, I can get the values (this is rather strange, but this happens, i.e. when the user logs in for the first time, this data is not available)
SharedPreferences, - ?