Android数据持久化SharedPreferences

 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();
            }
        }
    原文作者:张雨明
    原文地址: https://blog.csdn.net/yu540135101/article/details/87913709
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞