最近新出了很多好东西都没时间去好好看看,现在得好好复习下了,记下笔记

记得以前用的框架是android-async-http,volley啊,或者其它的,然后后面接着又出了okhttp,retrofit,rxjava很多新东西,有句话说的好啊,我不是程序员,我只是github上面的搬运工,出了这么多东西肯定会有很多人学习然后发表文章的,自己就去学习了下,因为以前用的是volley,所以就没去用retrofit了,因为volley也支持okhttp了,至于为什么要用okhttp就不多说了,毕竟不是大牛,只供小白学习,代码就是最好的老师啊,接下来就是用的okhttp和volley结合使用的框架体了。

接口请求类

 1 public class OkVolleyService {
 2 
 3     public interface ClientCallback {
 4         void onSuccess(Object data);
 5 
 6         void onFailure(Exception e);
 7 
 8         void onError(Exception e);
 9     }
10 
11     public static void Login(String userID, String password, Context context,
12                              final ClientCallback callback) {
13 
14         String token = AuthFactory.encryptPassword(userID);
15         Map<String, String> params = new HashMap<>();
16         params.put("token", token);
17         params.put("userName", userID);
18         params.put("userPassword", password);
19         RequestManager.PostString("/doctor/login.do", context, params,
20                 new Response.Listener<String>() {
21                     @Override
22                     public void onResponse(String response) {
23                         UsersEntity entity = null;
24                         try {
25                             entity = UsersEntity.parse(response);
26                         } catch (Exception e) {
27                             e.printStackTrace();
28                             callback.onError(e);
29                         }
30                         callback.onSuccess(entity);
31                     }
32                 }, new Response.ErrorListener() {
33                     @Override
34                     public void onErrorResponse(VolleyError error) {
35                         callback.onFailure(error);
36                     }
37                 });
38 
39     };
40 
41 }
View Code

相关文章:

  • 2021-05-12
  • 2022-12-23
  • 2021-08-25
  • 2021-11-23
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-18
  • 2021-08-31
  • 2021-05-15
  • 2022-12-23
  • 2021-12-11
  • 2021-09-10
相关资源
相似解决方案