android - onPostExecute() isn't getting invoked when the AsyncTask is executed from a nested event listener -
here's trying do: fetch json array remote server , render in list view (in new activity) when item selected list of items in popup. popup created when element in activity clicked/tapped. more specific: activity displays list of categories in grid view. each category has bunch of subcategories shown list of items in popup when user clicks on category. when user selects 1 of items in popup new activity created displays list of items in subcategory. item details fetched remote server json array. have created asynctask fetch item details server when sub-category selected popup. following code snippet this.
public class section extends fragment { ... @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { ... mgrid.setonitemclicklistener(new adapterview.onitemclicklistener() { public void onitemclick(adapterview <? > parent, final view v, nt position, long id) { ... popupmenu popup = new popupmenu(getactivity(), v); ... popup.setonmenuitemclicklistener(new popupmenu.onmenuitemclicklistener() { public boolean onmenuitemclick(menuitem item) { new getproductdatafromserver_task().execute(producturl); intent intent = new intent(getactivity(), productlistscreen.class); startactivity(intent); return true; } }); }); } return rootview; } }
the fragment part of activity used display category list in grid layout.
and, here asynctask fetches jsonarray server.
private class getproductdatafromserver_task extends asynctask < string, long, jsonobject > { @override protected jsonobject doinbackground(string...params) { httpentity httpentity = null; httpget httpget = null; try { defaulthttpclient httpclient = new defaulthttpclient(); httpget = new httpget(params[0]); httpresponse httpresponse = httpclient.execute(httpget); httpentity = httpresponse.getentity(); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } // convert httpentity json array jsonobject jsonobject = null; if (httpentity != null) { try { string entityresponse = entityutils.tostring(httpentity); jsonobject = new jsonobject(entityresponse); } catch (jsonexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } catch (illegalstateexception e) { e.printstacktrace(); } catch (exception e) { e.printstacktrace(); } } return jsonobject; } @override protected void onpostexecute(jsonobject jsonobject) { try { jsonarray products = jsonobject.getjsonarray("products"); int numproducts = products.length(); mproductlist = new productinfoforgridview[numproducts]; (int prodidx = 0; prodidx < numproducts; prodidx++) { mproductlist[prodidx] = getproductobjfromjsonobj(products.getjsonobject(prodidx)); } } catch (jsonexception e) { e.printstacktrace(); } } }
the issue facing onpostexecute() isn't getting invoked reason. jsonarray getting fetched server , doinbackground() function completes execution without exceptions. suspect has nested event listeners since works fine if start async task category listener (i.e. in onitemclick() - function invokes nested sub-category listener, setonmenuitemclicklistener()).
thanks in advance answer. have tried descriptive in question. glad provide more details if required.
are sure onpostexecute
not running. have tried yourgridadapter.notifydatasetchanged()
in onpostexecute
Comments
Post a Comment