java - Timer and TimerTask in android - further understanding -


i'm building app using camera2 api. i'm referencing google samples in github. problem couldn't understand why timer , timertask classes used when stopping recording video. hope in here. thank you.

here code :

 private void stoprecordingvideo() {     // ui     misrecordingvideo = false;     mbuttonvideo.settext(r.string.record);     // stop recording     try {         mpreviewsession.stoprepeating();         mpreviewsession.abortcaptures();     } catch (cameraaccessexception e) {         e.printstacktrace();     }      timer timer = new timer();     timertask timertask = new timertask() {         @override         public void run() {             mmediarecorder.stop();             mmediarecorder.reset();         }     };     timer.schedule(timertask,30);      startpreview(); } 

i want know
1. how timer , timetask working
2. how above classes combine each other
3. additionally major role in method?

firstly, should made clear timer , timertask parts of java.util, not belong android framework.
1. how timer , timertask working
timertask utility class implements runnable override run method perform defined task. meanwhile, timer helps schedule time , execute task. besides, task performed in background thread.
2. how above classes combine each other
described above, timertask define actual task , timer set alarm execute it.
3. additionally major role in method?
when call stoprecordingvideo(), timer used here turn off mediarecorder in background thread after 30 milliseconds. thought, main purpose of using timer here execute mediarecorder.stop() in background threa rather ui thread.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -