android - Create one AsyncHttpClient for each request, or to create one client for all requests -
i'm using android asynchronous http client .
which 1 true: create 1 asynchttpclient each request, or create 1 client requests.
now have 1 singltone requesthelper this:
private requesthelper() { mcontext = myapplication.getcontext(); baseurl = mcontext.getstring(r.string.base_url); } public static requesthelper getinstance() { if (instance == null) { instance = new requesthelper(); } return instance; } public void performloginrequest(string username, string password, gsonhttpresponsehandler gsonhttpresponsehandler) { asynchttpclient client = new asynchttpclient(); attachheaders(client); client.post(mcontext, baseurl + "/login", null, "application/json", gsonhttpresponsehandler); } public void getcountries(gsonhttpresponsehandler gsonhttpresponsehandler) { asynchttpclient client = new asynchttpclient(); client.get(mcontext, baseurl + "/countries", null, gsonhttpresponsehandler); } you can see i'm creating asynchttpclient object every request
i think creating 1 asynctask each request better code review. think both can done if manage each case , give right input asynctask let know function needs execute, might end 2000 lines class instead of 10 class of 200 lines explicit class name, anytime need change might need check whole 2000 lines , after changing need sure didn't break in class. matter of opinions.
Comments
Post a Comment