3

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;
            }
hasnain_ahmad
  • 325
  • 6
  • 17

1 Answers1

2

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!

Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78