public void run(){
setUpTTS();
try {
int i = (60-getSeconds())*1000;
Thread.sleep(i);//when screen off not work.
} catch (InterruptedException e) {
e.printStackTrace();
}
while (true){
tts.speak("Time: "+getTime(), TextToSpeech.QUEUE_FLUSH, null);
try {
Thread.sleep(wait);//when screen off not work.
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
此方法在java.class extends thread
当屏幕打开时,当屏幕关闭时,应用程序正在运行。 但在屏幕关闭(不充电)时不起作用 然后计数器将停止(Thread.sleep)