单个活动中的多个Volley请求

时间:2016-09-25 05:15:12

标签: android android-volley

我已在此<option selected="selected">中实施了Volley请求。只要调用此Activity方法,就会发送两次请求。此方法称为comment() onClickListner Button,当Activity点击放置在Button的卡片时,会启动Fragment

private void comment1(String id) {
    String url = "http://52.66.103.123:8000/comment/" + GlobalUtilityClass.getValueOnUserPrefernces(getContext(), "my_id") + "/" + id;
    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.e("comentfriend", response);
                   // Toast.makeText(getContext(), response, Toast.LENGTH_LONG).show();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("responsefriend_error", error.toString());

                    Toast.makeText(getContext(), error.toString(), Toast.LENGTH_LONG).show();
                }
            }) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> arguments = new HashMap<String, String>();
            arguments.put("commentName", edittext1);
            return arguments;
        }
    };
    RequestQueue requestQueue = Volley.newRequestQueue(getContext());
    requestQueue.add(stringRequest);
    stringRequest.setRetryPolicy(new DefaultRetryPolicy(
            6000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
}

0 个答案:

没有答案