SharedPreferences 保存数据

//public static final String PREFERENCESNAME = "vibrator"; 
public class Constant {
	public static final String CALLBACK = "callme";
	public static final String RING = "ring";
	public static final String VIBRATOR = "vibrator";
	public static final String PREFERENCESNAME = "MyPre";
	
}

引用
Context.MODE_PRIVATE:  指定该SharedPreferences的数据只能被本应用程序读、写;
Context.MODE_APPEND:新内容追加到原内容后;
Context.MODE_WORLD_READABLE:  指定 SharedPreferences数据能被其他应用程序读,但是不支持写;
Context.MODE_WORLD_WRITEABLE:  指定 SharedPreferences数据能被其他应用程序读、写。会覆盖原数据。
可以使用  +  连接这些权限。

SharedPreferences preferences = getSharedPreferences(
				Constant.PREFERENCESNAME, Context.MODE_PRIVATE);
		Editor edit = preferences.edit();
		edit.putBoolean("A", mCheckBox.isChecked());
				edit.commit();


猜你喜欢

转载自huiji232.iteye.com/blog/2064486