//采用android sharedpreferences 进行数据的保存读取
SharedPreferences sharedPreferences;
private final String mediaShare = "test";
private void InitMediaSharePreference() {
sharedPreferences = this.getSharedPreferences(mediaShare, MODE_PRIVATE);
}
//写入
String mdatStr = String.format("data_%d%d.yourdata", name1, name2);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(mdatStr, startMdatPlace);
editor.putString("STRING_KEY", "string");
editor.putBoolean("BOOLEAN_KEY", true);
editor.commit();
//查找
int startMdatPlace = sharedPreferences.getInt(
String.format("data_%d%d.yourdata", name1, name2), -1);
if (startMdatPlace != -1) {
//如果文件不存在
}
else{
//找到文件,读取
}
Android -- Sharedpreferences
最新推荐文章于 2024-04-25 17:09:07 发布