2017-02-03 89 views
-1

我向服務器發送請求並導致錯誤。我能夠將錯誤追溯到Volley不止一次發送請求的事實。我在網上搜索解決辦法,我嘗試了所有我所碰到,但他們都不來解決這個問題排隊發送多個請求Android

下面是我的代碼:

public void btnLogOut(View view) { 

    final ProgressDialog loading = ProgressDialog.show(this, "Logging Out", "Please wait...", false, false); 
    //cover.setVisibility(View.GONE); 
    String token = dbHelper.getAuth().getString(0); 

    String IP = helperFunctions.getAppUrl(); 
    final String url = IP + "/deregister?token=" + token+ "&appVersion=" + versionCode; 

    JsonObjectRequest sr = new JsonObjectRequest(Request.Method.POST, url,null, new Response.Listener<JSONObject>() { 
     @Override 
     public void onResponse(JSONObject response) { 
      loading.dismiss(); 
      logOut.LogOutUser(); 
     } 
    }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 

        if (VolleyErrorHelper.getMessage(error, Settings.this).equalsIgnoreCase("401")){ 
         logOut.MakeUserLogin(); 
        }else{ 
         cover.setVisibility(View.VISIBLE); 
        } 
        //VolleyLog.e("Deregister GCM", "Error: " + error.getMessage()); 
        loading.dismiss(); 
        Toast.makeText(Settings.this, "Process not completed, try again!", Toast.LENGTH_LONG).show();; 
       } 
      }); 
    sr.setRetryPolicy(new DefaultRetryPolicy(0, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 
    RequestQueue requestQueue = Volley.newRequestQueue(this); 
    requestQueue.add(sr); 
} 

回答

0

試試這個:

 sr.setRetryPolicy(new DefaultRetryPolicy(0, 0, DefaultRetryPolicy.DEFAULT_TIMEOUT_MS)); 

我用於POST請求,因此它可以執行重試