Skip to content Skip to sidebar Skip to footer

Get Sharedpreferences From A Service

I am trying to access shared preferences from a service. I have used the the following to save the value of text to a string... SharedPreferences sharedPreferences = getPreferences

Solution 1:

I'm always using PreferenceManager.getDefaultSharedPreferences(context). This is the same for all Contexts in your application.

A Service is a Context itself, so this would be sufficient:

PreferenceManager.getDefaultSharedPreferences(this);

Post a Comment for "Get Sharedpreferences From A Service"