现在的位置: 首页 > 综合 > 正文

DataDroid 刚开始接触和学习 二

2018年02月17日 ⁄ 综合 ⁄ 共 1495字 ⁄ 字号 评论关闭

Request 类 

这个类中一共做了四件事 

第一件事 设置内存缓存是否可用

    /**
     * Set whether the data returned from the {@link RequestService} must be cached in memory or
     * not.
     *
     * @param enabled Whether the data returned from the {@link RequestService} must be cached in
     *            memory or not.
     */
    public void setMemoryCacheEnabled(boolean enabled) {
        mMemoryCacheDataEnabled = enabled;
    }

这里内存实际只是一个开关设置实际实在RequestService中 定了了线程池来请求 加载 保存 读取数据 

第二件事 在每一次初始化中把数据名称和数据类型存起来(
这三个全局变量很关键  Request的每一个有参构造方法 把每一个数据类型 以键值对的形式  key存放在 mParamList value存放在 mTypeList中 再mBundle中存一份 )

   private final ArrayList<String> mParamList = new ArrayList<String>();
    private final ArrayList<Integer> mTypeList = new ArrayList<Integer>();
    private Bundle mBundle = new Bundle();

    /**
     * Add a CharSequence parameter to the request, replacing any existing value for the given name.
     *
     * @param name The parameter name.
     * @param value The parameter value.
     * @return This RequestData.
     */
    public Request put(String name, CharSequence value) {
        removeFromRequestData(name);
        mParamList.add(name);
        mTypeList.add(TYPE_CHARSEQUENCE);
        mBundle.putCharSequence(name, value);
        return this;
    }

第三件事:把之前存进去的数据原封不动的取出来

    /**
     * Returns the value associated with the given name, or (short) 0 if no mapping of the desired
     * type exists for the given name.
     *
     * @param name The parameter name.
     * @return A short value.
     */
    public short getShort(String name) {
        return mBundle.getShort(name);
    }

第四件事 删除存在的名称的value 

    private void removeFromRequestData(String name) {
        if (mParamList.contains(name)) {
            final int index = mParamList.indexOf(name);
            mParamList.remove(index);
            mTypeList.remove(index);
            mBundle.remove(name);
        }
    }

至此 可以看出Request只一个bean类 只一个中间暂时储存数据的类 没啥特别的

抱歉!评论已关闭.