【深蓝】Volley之Request 2.1

  这次关于的是Request的请求方面。肯定有些整理的不够详细。最后是要规划处Volley的整理框架图出来。

本人经常用的也就是两个请求GET POST 就从这两个请求开始讲起。

 

在Request类的最上方可以看到。

public abstract class Request<T> implements Comparable<Request<T>> 

他是一个抽象类,并且支持Comparable 也就是排序。

先去了解一下,必须要实现的功能是些什么,再了解排序。

1:必须实现的方法。

  1:abstract protected Response<T> parseNetworkResponse(NetworkResponse response); 

      根据Volley作者上面注释:

        

     * Subclasses must implement this to parse the raw network response and
     * return an appropriate response type. This method will be called from a worker thread. The response will not be delivered if you return null.

子类必须实现接信息 没有实现(没有加工的)网络响应和 返回一个适当的响应类型。

这个方法将会在一个工作线程被使用。 如果返回为null,这响应将不能在交付.发送

英语差的要命,但是计算机行业必学的一门语言,毕竟美帝的东西比我大中华要先进的好多,这是事实,这里不得吐槽一下了,中国生产硬件,而美国生产软件,软件,,呵呵 这个不用说了。除了人力成本,其他也没什么成本了。为什么小米一个卖手机的价值会这么高?因为MIUI,只是道听途说,如果不对,望纠正。

NetworkResponse 这个类上篇文章已经说明,封装了对应的请求。

Response  这个类是Volley自己定义的。

类注释:Encapsulates a parsed response for delivery.

封装解析响应交付, 在工作线程得到结果,肯定要give to Main Thread(英语一窍不通,必须要强硬头皮去学)

而Response内部直接定义了两个接口

    /** Callback interface for delivering parsed responses. */
    public interface Listener<T> {
        /** Called when a response is received. */
        public void onResponse(T response);
    }

1注释:回调接口 ,投递解析响应结果。

2注释:响应接收到时调用。

    

    /** Callback interface for delivering error responses. */
    public interface ErrorListener {
        /**
         * Callback method that an error has been occurred with the
         * provided error code and optional user-readable message.
         */
        public void onErrorResponse(VolleyError error);
    }

 

用过的也就知道,这个事处理解析返回回来错误的结果。

 

 

 

 

 

 

posted @ 2014-04-17 22:18  深蓝Android  阅读(148)  评论(0编辑  收藏  举报