Volley花了太长时间来处理请求

时间:2017-03-17 08:16:35

标签: android

我的Android应用程序有事件创建任务。它通过basr64格式编码发送图像,包括事件名称,事件位置,事件类型,事件开始日期和时间,事件结束日期和时间,事件类别,事件费用,事件描述,事件成本,最大参与者数量作为请求的参数。它花了太长时间差不多> 15秒。客户要求是它应该在5秒内处理。任何人都可以帮我实现这个目标吗?或任何加速凌空请求处理的技术。 IOS响应速度比android快。

Map<String, String> params = new HashMap<String, String>();
    params.put("eventname", etEventName.getText().toString().trim());
    params.put("userid", uid);
    params.put("lattitude", Double.toString(lat));
    params.put("longitude", Double.toString(longi));
    params.put("description", etEventDescription.getText().toString().trim());
    params.put("address", etEventLocation.getText().toString().trim());
    params.put("city", city);
    params.put("province", pro.trim());
    params.put("catid", caData);
    params.put("attendees", etEventPartcipentNumber.getText().toString().trim());
    params.put("startdate", startDate);
    params.put("starttime", starTime);
    params.put("enddate", endDate);
    params.put("endtime", endTime);
    params.put("eventtype", eventType);
    if (etEventFees.getText().toString().equals("") || etEventFees.getText().toString().equals(Fee)) {
        params.put("eventfee", "");
    } else {
        params.put("eventfee", etEventFees.getText().toString().substring(2).trim());
    }

    params.put("dayofweek", day);
    params.put("isprivate", privacy);
    params.put("profilepic", EventImage);
    params.put("myJid",mJid);
    params.put("openfirePsw",mPass);
    params.put("securityid", "MT0001");
    CustomeRequest create_eventRequest = new CustomeRequest(Request.Method.POST, urlCreateEvent, params, this.createeventSuccessResponseListener(), this.createeventErrorResponseListener());
    create_eventRequest.setRetryPolicy(new DefaultRetryPolicy(20000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    AppController.getInstance().addToRequestQueue(create_eventRequest);




public class CustomeRequest extends Request<JSONObject> {

private Response.Listener<JSONObject> listener;
private Map<String,String> params;

public CustomeRequest(String url,Map<String,String> params,Response.Listener<JSONObject> responseListener, Response.ErrorListener errorListener) {
    super(Method.GET,url, errorListener);
    this.listener=responseListener;
    this.params=params;
}

public CustomeRequest(int method, String url,Map<String, String> params,Response.Listener<JSONObject> responseListener, Response.ErrorListener errorListener) {
    super(method, url, errorListener);
    this.params=params;
    this.listener=responseListener;
}

@Override
public Map<String, String> getParams() {
    return params;
}

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
    Map<String,String> header=new HashMap<>();
    header.put("Content-Type","application/x-www-form-urlencoded");
    return header;
}

@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {

    try {
        String jsonString=new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        return Response.success(new JSONObject(jsonString),HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));

    } catch (JSONException je) {
        return Response.error(new ParseError(je));

    }

}

@Override
protected void deliverResponse(JSONObject response) {
    listener.onResponse(response);
}

}

0 个答案:

没有答案