Android asynctask waiting for anotherr asynctask -
public class getflyers extends asynctask<string, void, bitmap> { imageview imageview; int imagesize; context context; string url=""; string im=""; flyer fly; imagefragment i1; int position; public getflyers(imageview imageview, int imagesize, context conext,string im, flyer flu, imagefragment i1, int position ) { this.im = im; this.position = position; this.imageview = imageview; this.imagesize = imagesize; this.context=context; this.i1 = i1; fly = flu; } protected bitmap doinbackground(string... urls) { bitmap map = null; (string url : urls) { log.d("firste","image loaded back"); if(url != null && !url.trim().equals("")) { map = downloadimage(url); this.url = url; } } return map; } @override protected void onpostexecute(bitmap result) { } private bitmap downloadimage(string url) { bitmap bitmap = null; inputstream stream = null; bitmapfactory.options bmoptions = new bitmapfactory.options(); bmoptions.insamplesize = 1; try { stream = gethttpconnection(url); bitmap = bitmapfactory. decodestream(stream, null, bmoptions); } catch (ioexception e1) { e1.printstacktrace(); } { try { stream.close(); } catch(exception e) {
} } return bitmap; } // makes httpurlconnection , returns inputstream private inputstream gethttpconnection(string urlstring) throws ioexception { inputstream stream = null; url url = new url(urlstring); urlconnection connection = url.openconnection(); try { httpurlconnection httpconnection = (httpurlconnection) connection; httpconnection.setrequestmethod("get"); httpconnection.connect(); if (httpconnection.getresponsecode() == httpurlconnection.http_ok) { stream = httpconnection.getinputstream(); } } catch (exception ex) { ex.printstacktrace(); } return stream; } }
i have code, whenever called thread... lets 3 times.. getflyers task = new getflyers tasl.execute ... unfortunately 1 call per time moves on. 1 asynctask goes..i want run asynctask while running this
asynctasks executed serially default starting honeycomb.
to run asynctasks in parallel on platrorms, run as
if (build.version.sdk_int >= build.version_codes.honeycomb) { task.executeonexecutor(asynctask.thread_pool_executor); } else { task.execute(); } see
Comments
Post a Comment