简体   繁体   中英

Android Volley request not updating

I have a simple database/server setup that so far is working fine. And I have an app where I'm testing out how Volley works. Basically, I have a database of "users" where each JSON object has a unique ID, username, email, and password. I have a Volley function called updateUser upUser that takes the ID number for that person, as well as a new username. This function just changes the username for that user. So if I have ID: 5, User: test , and I type in my address bar: "stringServerURL:8080/upUser/5/newTEST" , it'll change the username for ID# 5 from test to newTEST . Works as intended so far.

From the android side, I have a method

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();
    }

The volleyHttpRequest r parameter is:

pDialog = new ProgressDialog(this.getApplicationContext());
final volleyHttpRequest request = new volleyHttpRequest(pDialog,0);

and the makearequest() method is:

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);
    }

So it doesn't crash or anything, and it seems to work, but when I pass in 5 for num and "newTEST" for str , nothing gets updated. I tried following the online tutorials as closely as possible, but it only works if I update it directly from the address bar.

I did find this in the "Log":

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)

I think it has something to do with the inactive input connection, but the server is running and I have no idea where to look.

Any help would be greatly appreciated.

Sometime volley save data in cache and give the same data many time you should first clear volley cache and then call data.

First use this to clear volley cache..

    Volley.newRequestQueue(context).getCache().clear();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM