I am using a PreferenceActivity to show some settings for my application. I am inflating the settings via a xml file so that my onCreate (and complete class methods) looks l
If you don't have access to getDefaultSharedPreferenes()
, you can use getSharedPreferences(name, mode)
instead, you just have to pass in the right name.
Android creates this name (possibly based on the package name of your project?). You can get it by putting the following code in a SettingsActivity
onCreate()
, and seeing what preferencesName
is.
String preferencesName = this.getPreferenceManager().getSharedPreferencesName();
The string should be something like com.example.projectname_preferences
. Hard code that somewhere in your project, and pass it in to getSharedPreferences()
and you should be good to go.