I have some shared preferences (latitude, longitude) that I want to access from a service, that is not subclassed from Activity.
In particular, when I try to access
If you have declared SharedPreferences as:
private static final String PREFS_NAME = "UserData";
private static final String PREFS_VALUE1 = "value1";
then use the below code to fetch values:
SharedPreferences preferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
value1 = preferences.getString(PREFS_VALUE1, "0");
In same way you can even save values to SharedPreferences.