Recently, I have been using the Volley library in android. It works great, but I was interested to learn about the most efficient way to update the user interface. I have a Utils class that has all Volley methods in it. Now I pass all the Views that will be updated as parameters, but I read that I can implement listeners in my activity, and then pass them as parameters in the Utils class ..
So my question is:
Which is more efficient and why updating the user interface looks like this:
public void getSettings(final TextView exampleView) {
JsonObjectRequest jsonRequest = new JsonObjectRequest(Method.GET,
url, (String) null, new Response.Listener<JSONObject>() {
public void onResponse(JSONObject response) {
try {
final String setting = getSettingFromJSON(response);
exampleView.setText(setting);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError arg0) {
}
});
app.add(jsonRequest);
}
Or I announce the listeners in my activity as follows:
Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
public void onResponse(JSONObject response) {
String setting = Utils.getSettingFromJSON(response);
exampleView.setText(setting);
}
};
then I pass them to my utils utility as parameters, so the call will be like this:
utils.getSettings(listener);
instead:
utils.getSettings(exampleView);
Thanks in advance:)