SelfGrowthUtil是一个工具类,调用selfgrowth方法,获取关键字自增长值

/**
 * Created by carey.cai on 8/26/2016.
 * SelfGrowthUtil是一个工具类,调用selfgrowth方法,获取关键字自增长值
 */
public class SelfGrowthUtil {
    //文件命名
    private static final String FILE_NAME = "Self_date";
    public static int selfgrowth(Context context){
        SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        if(sp.getInt("v",0)<=0){
            editor.putInt("v", (Integer)1001);
        }else{
            editor.putInt("v", (Integer) sp.getInt("v",0)+1);
        }
        editor.commit();
        return sp.getInt("v",0);
    }


}
发布了24 篇原创文章 · 获赞 22 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/cxscxs123cxs/article/details/53541659