java - Android right approach : where JSON response should be parsed - in UI thread, or in another one? -
i wondering - jsonobject
or jsonarray
received web-server should parsed in android app - in main ui or should delivered 1 ?
for example, i'm using volley library :
private void fetchresults(){ requestqueue queue = volley.newrequestqueue(mcontext); string url = authenticationrequester.url_get_all_orders; jsonarrayrequest jsondepartureobj = new jsonarrayrequest(url, new response.listener<jsonarray>() { @override public void onresponse(jsonarray jsonarray) { ivolleycallback.onjsonarraysuccess(jsonarray); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.d(tag, "error: " + error.getmessage()); // hide progress dialog } }); queue.add(jsondepartureobj); }
so should put ivolleycallback.onjsonarraysuccess(jsonarray);
in thread execution or can maintained the main ui thread ?
let's imagine incoming json big , needs time proceeded ?
the same question relates asynctask , other possible ways working web-services in android.
it prefered that, every task takes long time, should proccessed in another thread avoid overloading mainthread
:
asynctasks should ideally used short operations (a few seconds @ most.) if need keep threads running long periods of time, highly recommended use various apis provided java.util.concurrent package such executor, threadpoolexecutor , futuretask.
so if know have big data , take time, use new thread, if data small , takes less time, why take risk? move new thread too
Comments
Post a Comment