Jamie
Jamie

Reputation: 10886

Android RequestQueue

When I want to make a post request (with the volley libary) in a class called checkUserLogin I receive an error in my Queue:

enter image description here

This is my code:

private boolean request() {
    StringRequest stringRequest = new StringRequest(Request.Method.POST, LOGIN_URL,
            new Response.Listener<String>() {
                @Override
                public boolean onResponse(String response) throws JSONException {
                    checkLogin(response);
                    if(success.equals("true")){
                        return true;
                    }
                    else{
                        return false;
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public boolean onErrorResponse(VolleyError error) {
                    return false;
                }
            }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> map = new HashMap<String, String>();
            map.put(EMAIL, email);
            map.put(PASSWORD, password);
            return map;
        }
    };

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
    return false;
}

What's am I doing wrong with my RequestQueue?

Upvotes: 1

Views: 1409

Answers (1)

Blackbelt
Blackbelt

Reputation: 157457

The argument of newRequestQueue is a Context object. If you are getting a compile time error, it means that this is not referring to a Context object. The documentation suggest to use the ApplicationContext for the sake of newRequestQueue (see here). If you don't a context available in your class, you could think to subclass application and implement a singleton in order to be able to retrive it from everywhere

Upvotes: 1

Related Questions