【发布时间】:2013-07-19 04:39:48
【问题描述】:
我正在尝试了解 Android 的 SharedPreferences。我是初学者 也不是很了解。
我为我的应用偏好设置了这个类
public class Preferences {
public static final String MY_PREF = "MyPreferences";
private SharedPreferences sharedPreferences;
private Editor editor;
public Preferences(Context context) {
this.sharedPreferences = context.getSharedPreferences(MY_PREF, 0);
this.editor = this.sharedPreferences.edit();
}
public void set(String key, String value) {
this.editor.putString(key, value);
this.editor.commit();
}
public String get(String key) {
return this.sharedPreferences.getString(key, null);
}
public void clear(String key) {
this.editor.remove(key);
this.editor.commit();
}
public void clear() {
this.editor.clear();
this.editor.commit();
}
}
问题是我想设置默认首选项。它们将在安装应用程序时设置,并且可以在应用程序之后修改并保持持久性。 我听说有一个preferences.xml,但我不明白这个过程。
有人可以帮我吗?
感谢您的宝贵时间
【问题讨论】:
标签: android sharedpreferences default