Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is purpose of Map interface in android using volley library?

I have use the below code to implement the login system for my app. I have use “Map” Method. What is the purpose/function of the “Map” Method?

@Override
            protected Map<String, String> getParams() {
                // Posting parameters to login url
                Map<String, String> params = new HashMap<String, String>();

                params.put("email", email);
                params.put("password", password);

                return params;
            }
like image 264
hasnain_ahmad Avatar asked Nov 27 '25 11:11

hasnain_ahmad


1 Answers

If we want to post some data to a remote server we have to override getParams() method. In the Request class, getParams() is a method that returns null.

If we want to post some params, we have to return a Map with key value pair. In this case, we can override this method and sending three parameters tag, email, password:

@Override
protected Map<String, String> getParams() {
      // Posting parameters to login url
      Map<String, String> params = new HashMap<String, String>();
      params.put("tag", "login");
      params.put("email", email);
      params.put("password", password);
      return params;
}

In this case, we create a key called tag and pass the value login stored in param parameter.

Note: Notice that the getParams() is only called (by default) in a POST or PUT request, but not in a GET request.

I hope it helps!

like image 136
Rajesh Avatar answered Nov 30 '25 00:11

Rajesh