String key = "AnimationTimes";
SharedPreferences read = getApplicationContext().getSharedPreferences("makeStory", Context.MODE_PRIVATE);
if (read != null) {
int value = read.getInt(key, 0);
if (value == 1) {
return;
}else {
//步骤1:创建一个SharedPreferences.Editor接口对象
SharedPreferences.Editor editor = getApplicationContext().getSharedPreferences("makeStory", Context.MODE_PRIVATE).edit();
//步骤2-2:将获取过来的值放入文件
editor.putInt(key, ++value);
//步骤3:提交
editor.commit();
}
}
Android数据持久化SharedPreferences
最新推荐文章于 2021-08-11 15:27:54 发布