I need to start the task "listen to the microphone", which should work for a certain time in seconds and then stop. How to organize this delay before stopping?
2 answers
Alternatively, you can use the java.util.Timer class.
Timer timer = new Timer(true); timer.schedule(new TimerTask() { @Override public void run() { //выключение микрофона } }, TimeUnit.DAYS.toMillis(1)); the run method in this example will start in 1 day
|
And you can still
new Handler().postDelayed(new Runnable(){...},1000) And if you're handsome and use the RX, then
Observable.timer(1000, TimeUnit.MILLISECONDS) .subscribe(t -> {...}) - Ps ... Typo! - D-side
|