我有應用程序與計時器。當我按下電源按鈕時,我的應用進入睡眠模式並停止計時。我應該怎麼做計時器繼續工作。下面我非常簡單的代碼計時器。Android應用不能在睡眠模式下工作
Thread t = new Thread(){
@Override
public void run() {
while (!isInterrupted()){
try {
Thread.sleep(1000);
i++;
Log.e("pokaz "," i "+i);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
看看這個:http://stackoverflow.com/questions/10725711/how-to-do-not-let-thread-stop-theme-self-when-in-standby-mode – 476rick