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;
}
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With