SharedPreferences用于存储数据

    /**
     * 获取登陆标识,判断是否为首次登陆
     *
     * @return
     */
    public static int loadLoginFlag(Context mContext)
    {
        SharedPreferences preference = mContext.getSharedPreferences(GConst.HAIER_FIRST_LOGIN, Context.MODE_PRIVATE);

        // android.content.SharedPreferences.getInt(String key, int defValue)
        int flag = preference.getInt(GConst.FIRST_LOGIN, GConst.IS_FIRST_LOGIN);
        return flag;
    }

    /**
     * 保存时同时修改登陆标识为非首次登陆
     */
    public static void saveNotFirst(Context mContext)
    {
        SharedPreferences preference = mContext.getSharedPreferences(GConst.HAIER_FIRST_LOGIN, Context.MODE_PRIVATE);
        Editor editor = preference.edit();

        // android.content.SharedPreferences.Editor.putInt(String key, int value)
        editor.putInt(GConst.FIRST_LOGIN, GConst.NOT_FIRST_LOGIN);
        editor.commit();
    }

posted on 2012-11-09 10:41  勤修  阅读(187)  评论(0编辑  收藏  举报

导航