Android HTTP GET和POST SLOW

时间:2014-05-17 03:13:09

标签: android performance android-volley

我正在使用android volley和我的httppost并且获取需要一段时间来执行或不执行,10 +秒。我无法弄清楚造成这种情况的原因和解决办法。

logcat的:

05-16 17:13:42.237: D/RenderPolicy(30189): ViewRootImpl.enableHardwareAcceleration -> enableRenderPolicy
05-16 17:13:42.287: D/libc(30189): [NET] getaddrinfo+,hn 13(0x736e61706d792e),sn(),family 0,flags 4
05-16 17:13:42.287: D/libc(30189): [NET] getaddrinfo-,err=8
05-16 17:13:42.287: D/libc(30189): [NET] getaddrinfo+,hn 13(0x736e61706d792e),sn(),family 0,flags 1024
05-16 17:13:42.287: D/libc(30189): [NET] getaddrinfo-, 1
05-16 17:13:42.287: D/libc(30189): [NET] getaddrinfo_proxy+
05-16 17:13:42.808: D/libc(30189): [NET] getaddrinfo_proxy-, success

05-16 16:59:29.077: D/Volley(30189): [27527] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://mysitedomain.com 0x3ef6da79 NORMAL 1> [lifetime=12023], [size=78957], [rc=200], [retryCount=0]
05-16 16:59:38.677: D/Volley(30189): [1] Request.finish: 21664 ms: [ ] http://mysitedomain.com 0x3ef6da79 NORMAL 1

更新添加了用于拨打凌空电话的Android代码:

String token = savedtokens;
 RequestQueue queue = Volley.newRequestQueue(getBaseContext());  // this = context
    final String url = "http://mydomainsite/services/api/rest/json/?method=messages.inbox&api_key=kdjfk8374jdhfjdh&username="+loggedinusername+"&auth_token="+token+"";
    System.out.println("NOTIFICATION_____:" + url);
    final JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET,
               url, null,
               new Listener<JSONObject>() {
          private String html;
        JSONArray river = null;
        private String guid;
        private String avatar_url;
        private String type;
        private String from_guid;
        private String description;
        private String time_created;
        private String addcommentline;



        @Override
          public void onResponse(JSONObject response) {
              // response
              System.out.println("Wire___________:" + response);
              html ="";
                try {




                   try {
                        // Getting Array of Contacts
                        river = response.getJSONArray("result");


                        // looping through All Contacts
                        for(int i = 0; i < river.length(); i++){
                            JSONObject c = river.getJSONObject(i);
                            if (c.has("guid")) {
                                guid = c.getString("guid");                     
                             System.out.println("guid:"+guid); }

                            if (c.has("username")) {
                                username = c.getString("username");                     
                             System.out.println("username:"+username); }

                            if (c.has("avatar_url")) {
                                avatar_url = c.getString("avatar_url");                     
                             System.out.println("avatar_url:"+avatar_url); }

                            if (c.has("type")) {
                                type = c.getString("type");                     
                             System.out.println("type:"+type); }

                            if (c.has("from_guid")) {
                                from_guid = c.getString("from_guid");                   
                             System.out.println("from_guid:"+from_guid); }



                            if (c.has("description")) {
                                description = c.getString("description");                   
                             System.out.println("description:"+description); }

                            if (c.has("time_created")) {
                                time_created = c.getString("time_created");                     
                             System.out.println("time_created:"+time_created); }

                            if (c.has("guid")) {  
                                guid = c.getString("guid");                       
                             System.out.println("guid:"+guid); }



                        html = "<a href='http://mydomainsite.com/services/api/rest/json/?method=user.profile&username="+username+"&limit=1000&offset=0&loggedinusername="+loggedinusername+"&getuserphotos'>"+"<img src="+avatar_url+" style='border-radius:60px;vertical-align:middle;width:10%'>"+username +"</a>"+": "+ type+ "<br>"+html; 

                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }catch(Exception e)
                {
                        e.printStackTrace();
                }     

                System.out.println("ITLOADED");

                String summary = "<html><body>+html+</body></html>";
             wv.loadUrl("about:blank");
            wv.loadData(summary, "text/html", null);



          }
      },
      new ErrorListener()
      {
           @Override 
           public void onErrorResponse(VolleyError error) {
               // error
              // Log.d("Error.Responser", error);
               System.out.println("Volley response2___________:" + error);
         }
      }
   ) {    

   };
   jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
            20000, 
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
   queue.add(jsonObjReq);

0 个答案:

没有答案