1
我想將我的應用程序超時時間設置爲60秒,這意味着我的應用程序只會在ProgressDialog從服務器獲取答覆或達到超時但未從服務器獲得答覆時關閉ProgressDialog。排球setRetryPolicy超時不起作用
目前我與排球庫工作在Android上,所以這是我做的:
private void loginOnline(final String user, final String pwd, final String login_url){
final ProgressDialog pd = new ProgressDialog(this);
pd.setMessage("Communicating with Server");
pd.show();
final RequestQueue queue = Volley.newRequestQueue(this);
Map<String, String> params = new HashMap<String, String>();
params.put(KEY_USERNAME, user);
params.put(KEY_PASSWORD, pwd);
final JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST, login_url, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
pd.dismiss();
try {
int msg = response.getInt("status");
sendMessage(msg);
}
catch (JSONException e){
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pd.dismiss();
Log.d("D", "onErrorResponse: "+error.getMessage());
}
});
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(60000,0,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(jsonObjReq);
}
問題是,當我嘗試連接到我的服務器,它顯示在日誌中:
D/D: onErrorResponse: java.net.ConnectException: failed to connect to /192.123.x.xxx (port 3000) after 60000ms: isConnected failed: EHOSTUNREACH (No route to host)
D/Volley: [1] Request.finish: 3072 ms: [ ] http://192.123.4.215:3000/login 0xdde27c7c NORMAL 1
我的問題是爲什麼它停止連接到服務器之前,它達到60000毫秒。 在此先感謝
感謝您的回答! – VincentTheonardo