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);
    }


}

你可能感兴趣的:(Android)