java - How to set delay time for the AsyncTask execution when it uses also another Thread? -
i set delay time in milliseconds class extends asynctask. class using java thread. there classes stream mjpeg on android few changes question: android ics , mjpeg using asynctask
this class extends asynctask:
public class getcameramjpeg extends asynctask<string, void, mjpeginputstream> { @override protected mjpeginputstream doinbackground(string... params) { try { url url = new url(params[0]); httpurlconnection connection = (httpurlconnection) url.openconnection(); connection.setrequestmethod("get"); if (username != null && password != null) { string authencoded = base64.encodetostring((username + ":" + password).getbytes(), base64.default); connection.setrequestproperty("authorization", "basic " + authencoded); } connection.connect(); return new mjpeginputstream(connection.getinputstream()); } catch (malformedurlexception e) { e.printstacktrace(); } catch (protocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return null; } @override protected void onpostexecute(mjpeginputstream result) { mjpegview.setsource(result); mjpegview.setdisplaymode(mjpegview.size_fullscreen); } }
mjpeginputstream
class same in stackoverflow question pasted above. , mjpegview
class extending surfaceview. contains inner class mjpegviewthread
class extending java thread
class. , run
method of thread.
@override public void run() { bitmap bitmap; rect destrect; canvas canvas = null; while (mjpegrun) { if (surfacedone) { try { canvas = surfaceholder.lockcanvas(); if (canvas != null) { synchronized (surfaceholder) { try { bitmap = mjpeginputstream.readmjpegframe(); if (displaymode != size_fullscreen) { displaywidth = bitmap.getwidth(); displayheight = bitmap.getheight(); } destrect = destrect(bitmap.getwidth(), bitmap.getheight()); canvas.drawcolor(color.transparent); canvas.drawbitmap(bitmap, null, destrect, new paint()); } catch (ioexception e) { e.getstacktrace(); log.d(tag, "catch ioexception hit in run", e); } } } } { if (canvas != null) { surfaceholder.unlockcanvasandpost(canvas); } } } } }
i have tried answer: how execute async task repeatedly after fixed time intervals there not noticeable difference. suppose mjpegview
runs own java thread
.
use handler handler h = new handler(); h.postdelay(function, time);
Comments
Post a Comment