我有一个简单的数据库/服务器设置,到目前为止运行良好。我有一个应用程序,我正在其中测试 Volley 的工作原理。
基本上,我有一个“用户”数据库,其中每个 JSON 对象都有唯一的 ID、用户名、电子邮件和密码。
我有一个名为 updateUser upUser
的 Volley 函数它获取该人的 ID 号以及新的用户名。此函数只是更改该用户的用户名。所以如果我有ID: 5, User: test
,然后我在地址栏中输入:"stringServerURL:8080/upUser/5/newTEST"
,它会将 ID# 5 的用户名从 test
更改为至newTEST
。到目前为止,按预期工作。
从android端,我有一个方法
public void updateRecords(volleyHttpRequest r, String info, int id){
final volleyHttpRequest req = r;
final String str = info;
final int num = id;
new Thread(new Runnable() {
@Override
public void run() {
req.makearequest("http://some-server-address:8080/upUser/" + num + "/" + str);
}
});
// Toast.makeText(getApplicationContext(), "Username updated.", Toast.LENGTH_SHORT).show();
}
volleyHttpRequest r
参数为:
pDialog = new ProgressDialog(this.getApplicationContext());
final volleyHttpRequest request = new volleyHttpRequest(pDialog,0);
和makearequest()
方法是:
public void makearequest(String url) {
StringRequest strReq = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
hideProgressDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hideProgressDialog();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
所以它不会崩溃或发生任何事情,而且它似乎可以工作,但是当我为 num
传递 5 时和 str
的“newTEST” ,没有任何更新。我尝试尽可能严格地遵循在线教程,但只有直接从地址栏更新它才有效。
我确实在“日志”中找到了这个:
D/EGL_emulation: eglMakeCurrent: 0xea072a00: ver 3 0 (tinfo 0xd690b5e0)
D/EGL_emulation: eglMakeCurrent: 0xea072a00: ver 3 0 (tinfo 0xd690b5e0)
D/OpenGLRenderer: endAllActiveAnimators on 0xd602b680 (RippleDrawable) with handle 0xd69882a0
W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
D/EGL_emulation: eglMakeCurrent: 0xea072a00: ver 3 0 (tinfo 0xd690b5e0)
W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
D/EGL_emulation: eglMakeCurrent: 0xea072a00: ver 3 0 (tinfo 0xd690b5e0)
我认为这与非 Activity 输入连接有关,但服务器正在运行,我不知道该去哪里查看。
任何帮助将不胜感激。
最佳答案
有时volley会将数据保存在缓存中,并且多次给出相同的数据,您应该先清除volley缓存,然后再调用数据。
首先用它来清除volley缓存..
Volley.newRequestQueue(context).getCache().clear();
关于java - Android Volley 请求未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59313681/