PreferenceFragment
is easy to create a configuration screen, but it assumes that you use the default SharedPreferences
and can only edit global settings in the app.
Would it be possible to link any SharedPreferences
by name to the PreferenceFragment
screen?The original purpose is to easily implement the App Widgets instance-specific configuration screen.
Before calling addPreferencesFromResource(R.xml.preferences)
in the PreferenceFragment onCreate, you can specify the name of the SharedPreferences to use by using getPreferenceManager().setSharedPreferencesName
.
getPreferenceManager().setSharedPreferencesName(name)?See you.
Do you mean PreferenceManager#getDefaultSharedPreferences when you say getDefaultSharedPreferences on which PreferenceFragment depends?
Once you have set the name in PreferenceManager#setSharedPreferencesName, do not use PreferenceManager#getDefaultSharedPreferences, but use the name you set in PreferenceManager#getSharedPreferences or Context#getSharedPreferences
The SharedPreferences name returned by PreferenceManager#getDefaultSharedPreferences is hardcoded with "package name +_preferences" as far as the source code goes, so it is unlikely to be changed.
926 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
620 GDB gets version error when attempting to debug with the Presense SDK (IDE)
577 Who developed the "avformat-59.dll" that comes with FFmpeg?
631 Uncaught (inpromise) Error on Electron: An object could not be cloned
575 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.