gpt4 book ai didi

android - Volley : requests are being sent twice

转载 作者:行者123 更新时间:2023-12-05 00:14:20 33 4
gpt4 key购买 nike

我知道这个网站上有类似的问题,我已经尝试了一些建议的解决方案,其中一些对之前提出这个问题的人有效。但是,我仍然收到发送两次而不是一次的相同数据。
这是代码:

final ProgressDialog progressDialog = DialogsUtils.showProgressDialog(DirectSendActivity.this, getResources().getString(R.string.sending));
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
StringRequest stringRequest = new StringRequest(Request.Method.POST,
direct_send_url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean succcess = jsonResponse.getBoolean("success");
if (succcess) {
onSendSuccess();
progressDialog.dismiss();
} else {
onSendFailed();
progressDialog.dismiss();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
NetworkResponse networkResponse = error.networkResponse;
Log.e(TAG, "Volley error: " + error.getMessage() + ", code: " + networkResponse);
Toast.makeText(getApplicationContext(), "Volley error: " + error.getMessage(), Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
Snackbar.make(findViewById(android.R.id.content), getResources().getString(R.string.connection_problem) , Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}){
@NonNull
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("method",method);
params.put("amount", a_mount + "");
params.put("recipient",recipient);
params.put("reason",reason);
params.put("user_id",user_data.getString("uidkey", null));
Log.e(TAG, "Params: " + params.toString());
return params;
}
};
stringRequest.setRetryPolicy(new DefaultRetryPolicy(0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
MyApplication.getInstance().addToRequestQueue(stringRequest);
}
}, 3000);

最佳答案

在将请求添加到请求队列之前添加这个

request.setRetryPolicy(new DefaultRetryPolicy(
0,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

关于android - Volley : requests are being sent twice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41493203/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com