如何在安卓中创建和获取首选项值



代码: https://github.com/DanSolomon/CMSC434-Clock

单独的设置活动中有一个首选项(以 xml/pref_general.xml 为单位)。我需要能够存储首选项的当前值并在主活动中获取值。

我无法弄清楚它是否正确存储了值,如果是,如何从存储中获取值。

它在 SettingsActivity 中:

PreferenceManager .getDefaultSharedPreferences(preference.getContext()) .getString(preference.getKey(), ""));

而 preference.getKey() 是 xml 定义中的键。

最新更新