lately I'm using Volley library in android.. It works fine but I was wondering about the most efficient way of updating the UI.. I have a Utils class that has all the Volley methods.. right now I pass all the Views that will be updated as parameters, but I've read that I could implement the listeners in my activity then pass them as parameters in the Utils class..
So my question is:
Which is more efficient and why updating the UI 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 declare the listeners in my activity like this :
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 into my utils function as parameters so the call would be like this :
utils.getSettings(listener);
instead of :
utils.getSettings(exampleView);
Thanks In Advance :)