Volley StringRequest Post仅适用于android 2.3.6

时间:2016-08-18 13:23:13

标签: android android-volley

evry的东西在我的手机2.3.6上得到了很好的发布,但在4.0.1和lolipop和marshmallo并没有发布任何东西,我确定所有的参数都填满了,更多的评论在代码中进一步解释。可能是因为我正在使用try..finally里面的凌空反应试试?正如我所说,android 2.3.6没有问题,这让我疯狂

    private void pub(//final strings for params) {
    String tag_string_req = "pubb";
    String url = "http://.....";
    rl.setVisibility(View.VISIBLE);
    donutprogress.setProgress(12);//this thing works on UI
    StringRequest strReq = new StringRequest(Request.Method.POST,
            url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Log.d("TAG", "Register Response: " + response.toString());
            try {
                JSONObject jObj = new JSONObject(response);
                donutprogress.setProgress(donutprogress.getProgress() + 43);
                JSONObject adimg = jObj.getJSONObject("somthing");
                final Number adId = ((Number) adimg.get("id"));
                //String responsemessage = jObj.getString("message");
                //progress.setText(responsemessage);
                try {
               //some stuf after posting pot not the cause of problem it is not posting in first place
                } finally {
                    Thread t5 = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                Intent intent = new Intent(Activitythis.this,
                                        Activitymain.class);
                                startActivity(intent);
                            } catch (Exception ex) {
                                ex.printStackTrace();
                            }
                        }
                    });
                    t5.start();
                    try {
                        t5.join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError response) {
            pub(//params strings);
        }
    }) {

        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            // Posting params to register url
            Map<String, String> params = new HashMap<String, String>();
            params.put("title", tite);
            //other params............
            params.put("Content-Type", "application/json; charset=utf-8");

            return params;
        }

    };
    strReq.setRetryPolicy(new DefaultRetryPolicy(0,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}

0 个答案:

没有答案