Harmony 鸿蒙 类Android安卓SharedPreferences的使用,Preferences
public class SpUtils {
public static void put(Context context,boolean ischeck){
DatabaseHelper databaseHelper = new DatabaseHelper(context);
String filename = "pdb";
Preferences preferences = databaseHelper.getPreferences(filename);
//插入数据,可以是string,int等等类型
preferences.putBoolean("IsCheck",ischeck);
preferences.flush();
}
public static boolean get(Context context){
DatabaseHelper databaseHelper = new DatabaseHelper(context);
String filename = "pdb";
Preferences preferences = databaseHelper.getPreferences(filename);
//String fruit = preferences.getString("fruit", "");
//int number = preferences.getInt("number", 0);
boolean ischeck = preferences.getBoolean("IsCheck",false);
return ischeck;
}
public static void remove(Context context){
DatabaseHelper databaseHelper = new DatabaseHelper(context);
String filename = "pdb";
Preferences preferences = databaseHelper.getPreferences(filename);
databaseHelper.deletePreferences(filename);
preferences.clear();
}
}