{"action":"created","issue":{"url":"https://api.github.com/repos/android-cn/android-discuss/issues/222","labels_url":"https://api.github.com/repos/android-cn/android-discuss/issues/222/labels{/name}","comments_url":"https://api.github.com/repos/android-cn/android-discuss/issues/222/comments","events_url":"https://api.github.com/repos/android-cn/android-discuss/issues/222/events","html_url":"https://github.com/android-cn/android-discuss/issues/222","id":100445842,"number":222,"title":"网络请求的思考","user":{"login":"BelongsH","id":6235014,"avatar_url":"https://avatars.githubusercontent.com/u/6235014?v=3","gravatar_id":"","url":"https://api.github.com/users/BelongsH","html_url":"https://github.com/BelongsH","followers_url":"https://api.github.com/users/BelongsH/followers","following_url":"https://api.github.com/users/BelongsH/following{/other_user}","gists_url":"https://api.github.com/users/BelongsH/gists{/gist_id}","starred_url":"https://api.github.com/users/BelongsH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BelongsH/subscriptions","organizations_url":"https://api.github.com/users/BelongsH/orgs","repos_url":"https://api.github.com/users/BelongsH/repos","events_url":"https://api.github.com/users/BelongsH/events{/privacy}","received_events_url":"https://api.github.com/users/BelongsH/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-08-12T01:15:52Z","updated_at":"2015-08-13T08:49:29Z","closed_at":null,"body":"\r\n1,在发起网络请求前，一般先会showLoading();>>加载对话框.\r\n2.存在Callback接口里面有一个onSuccess(int code,String result)和onFail(NetError fail)方法，具体实现类，在具体ui层实现。\r\n3.所有的网络请求，都会经过同一个方法进行发送wrapParam();>>>包装参数\r\n4.使用volley对StringRequest进行重写，在StringRequest中对同一对所有respons进行一层解析。（会判断一些错误信息，如token出错。或操作失败。调用callBack的onFail()方法）\r\n5.在每一个需要网络请求的UI层中，存在有callback的实现，然后对code进行判断。刷新相对应的界面。\r\n\r\n出现的问题，\r\nA。在每一个网络请求之前都会调用。showLoading(); \r\nB。每一个需要网络请求的界面都需要一个CallBack实例，然后根据code来判断是哪一个请求。\r\nC。每一个Callback里面都存在OnFail()的方法，而且里面的代码相似度极高。\r\nD。callBack里面根据Swicth来判断是那个请求，阅读起来非常的差。\r\n\r\n希望知道现在主流的公司，对网络请求的封装，或则说设计是怎么处理的。"},"comment":{"url":"https://api.github.com/repos/android-cn/android-discuss/issues/comments/130579168","html_url":"https://github.com/android-cn/android-discuss/issues/222#issuecomment-130579168","issue_url":"https://api.github.com/repos/android-cn/android-discuss/issues/222","id":130579168,"user":{"login":"tanxiaoluo","id":3716780,"avatar_url":"https://avatars.githubusercontent.com/u/3716780?v=3","gravatar_id":"","url":"https://api.github.com/users/tanxiaoluo","html_url":"https://github.com/tanxiaoluo","followers_url":"https://api.github.com/users/tanxiaoluo/followers","following_url":"https://api.github.com/users/tanxiaoluo/following{/other_user}","gists_url":"https://api.github.com/users/tanxiaoluo/gists{/gist_id}","starred_url":"https://api.github.com/users/tanxiaoluo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tanxiaoluo/subscriptions","organizations_url":"https://api.github.com/users/tanxiaoluo/orgs","repos_url":"https://api.github.com/users/tanxiaoluo/repos","events_url":"https://api.github.com/users/tanxiaoluo/events{/privacy}","received_events_url":"https://api.github.com/users/tanxiaoluo/received_events","type":"User","site_admin":false},"created_at":"2015-08-13T08:49:29Z","updated_at":"2015-08-13T08:49:29Z","body":"@BelongsH 如果每一次用完showLoading，在关闭的函数中把dialog == null 一把呢？"}}