I am using Preference Manager for set and get the global value in my application.
In application there is one service in which I am getting data from device,passing that data to server through API and getting some data in response through API.
I am storing the response which I get into one variable of SharedPreference as below:
//To store value
edit = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
edit.putString(Settings.PREF_SIPARRAY + "",test);
edit.commit();
edit.apply();
//To get value
test = PreferenceManager.getDefaultSharedPreferences(ctx).getString(Settings.PREF_SIPARRAY + "",Settings.DEFAULT_SIPARRAY);
Log.v("contact_sync*****", "" + test);
I am getting data in above line perfectly. But when I am going to some other activity and trying to get data with same code as above then I am not getting anything.
Every 15 minutes service will do same process as I have explained. When second time service will fetch the data and set in share preference's variable then in activity I can able to get data.
Sometimes I can get data at first time in activity but some times I can not. Does anybody know why this is happening?
Every time from service data set perfectly in shared preference’s variable then why I can not able to get data in activity?
Please help me for above.