我需要在首选项 XML 中设置的默认值在首次运行时可用。
在某些手机中这有效,但其他一些手机(例如三星)表现得非常奇怪。
在我的特殊情况下,以下代码:
String key = "@string/timeout_key"
timeout = Integer.valueOf(prefs.getString(key, "10"));
尽管首选项 XMLtimeout
指定prefs.getString()
:
android:defaultValue="5"
字符串“timeout_key”存在,我可以验证它是否被正确读取。
我目前的“手动解决方法”是调用设置编辑器,重新输入设置并按 OK。
有没有办法以编程方式做到这一点?