java - I need to execute the function only for n times and then stop -
in below code, want take picture execute n times , stop.
i tried using loop error java.lang.illegalstateexception: session has been closed; further changes illegal
.
protected void onresume() { super.onresume(); log.e(tag, "onresume"); startbackgroundthread(); if (textureview.isavailable()) { opencamera(); } else { textureview.setsurfacetexturelistener(texturelistener); } final timer timer = new timer(); timer.schedule(new timertask() { public void run() { takepicture(); } }, 200, 15000); }
you can use count of taken pictures , cancel timer like:
protected void onresume() { super.onresume(); log.e(tag, "onresume"); startbackgroundthread(); if (textureview.isavailable()) { opencamera(); } else { textureview.setsurfacetexturelistener(texturelistener); } final int pictures_limit = 10; final timer timer = new timer(); timer.schedule(new timertask() { int pictureno = 0; public void run() { takepicture(); pictureno++; if (pictureno>pictures_limit) { timer.cancel(); } } }, 200, 15000); }
Comments
Post a Comment